repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

🧪 new nu command `github-upload-key`

6ba60db552c5ea49c94f0b86328c906c589f6182

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

in order to be able to add ssh keys easily to github without having to
install the github cli, a command was created that can take care of it
via a rest post call.

Changed files (6)

+131 / −62 text lines

Diff layout

TODO.md

Modified

+35 / −3 text lines

1# To Do
1# To-Do
3- [ ] what to do about ssh and GPG keys? or secrets in general?
3## Commands to remember
4
5- sd: search and replace
6- fd: find files recursively
7- diskonaut: explore file system visually for large files
8- btm (bottom): system overview
9- grep (rg): search file contents
10- bat: show file content
11- glow: render markdown in the terminal
12- tokei: count lines of code
13- hyperfine: benchmark tool
14- tldr: tool documentation
15- grex: regular expression pattern generator
16- xh: make HTTP requests
17- watchexec: filesystem watcher
18- licensor: print a license text
19- pastel: manage colors
20- hexyl: terminal hex viewer
21- gib: generate gitignore files
22- ix (indexa): global file search
23- silicon: code pretty picture generator
24- eva: calculator
25- bandwhich: show network traffic information
26- so: search Stack Exchange
28## Stuff to do
30- [ ] kill thy babbies: remove obsolete java commands. nu has builtins now for checksums and for random uuids
31- [ ] rewrite bootstripper and java commmands with zig. how to run them? precompile? zig run?
33## Done
35- [x] what to do about ssh and GPG keys? or secrets in general?
436 - [x] say goodbye to GPG, too hard to manage.
5- [ ] how to handle java tools in `tools` cross platform?
37- [x] how to handle java tools in `tools` cross platform?

neovim/lua/lsp.lua

Modified

+6 / −1 text lines

2222 chain_complete_list = chain_complete_list,
2323 })
25 -- hook lsp into vim autocomplete in insert mode
26 vim.api.nvim_buf_set_option(buffer_number, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
2528 local map = function(type, key, value)
2629 vim.api.nvim_buf_set_keymap(buffer_number, type, key, value, { noremap = true, silent = true })
2730 end
127130 })
129132 -- Zig LSP
130 lsp.zls.setup({ on_attach = integrate_into_neovim })
133 -- FIXME: ZLS is very tied to the specific version of the zig compiler one uses.
134 -- we need to build our own version for 0.8.0 because it is not done upstream yet
135 -- lsp.zls.setup({ on_attach = integrate_into_neovim })
132137 -- LLVM Clang LSP
133138 lsp.clangd.setup({ on_attach = integrate_into_neovim })

nushell/nu/config/config.toml

Modified

+8 / −0 text lines

1212startup = [
1313"zoxide init nushell --hook prompt | save zoxide.nu",
1414"source zoxide.nu",
15 # loading of plugins in nu seems inconsistent.
16 # the only get loaded in interactive nu session.
17 # not for scripts and --commands.
18 # see https://github.com/nushell/nushell/issues/3892
19"nu plugin --load (build-string $nu.env.CARGO_HOME / bin)",
1520"source nurc",
5964[env]
6065STARSHIP_SHELL = "nushell"
66EDITOR = "nvim"
67BAT_THEME = "Nord"
68_ZO_ECHO = 1

nushell/nu/config/nurc

Modified

+67 / −40 text lines

33# `startup = ["source ~/.config/nushell/nurc"]`
55# GLOBAL VARIABLES
6let TODO_FILE = D:/Notizen/TODO.md
7let NURC = (build-string (config path | path dirname) /nurc)
8let OS = (sys).host.name
6let-env NURC = (build-string (pwd) /nurc)
7let-env DOTFILES = ((build-string (pwd) /../../..) | path expand)
109# ALIASES
1110alias cat = bat
1615alias grep = rg
1817# CUSTOM LITTLE JAVA COMMANDS
19alias sha = java_tool sha
20alias uuid = java_tool random_uuid
21alias download = java_tool download
22alias download_jar = java_tool download_jar
18alias sha = java (build-string $nu.env.DOTFILES /tools/ sha.java)
19alias aes = java (build-string $nu.env.DOTFILES /tools/ aes.java)
20alias uuid = java (build-string $nu.env.DOTFILES /tools/ random_uuid.java)
21alias download = java (build-string $nu.env.DOTFILES /tools/ download.java)
22alias download_jar = java (build-string $nu.env.DOTFILES /tools/ download_jar.java)
2424# FUNCTIONS
26# Wrapper function to launch my custom java tool scripts.
27# This function handles the different paths the tools can have on different hosts.
28def java_tool [
29 name: string # name of the custom java tool script without the .java extension
26# Uploads a PUBLIC ssh key to GitHub.
27# Will prompt for the AES encryption password of my dotfiles.
28def github-upload-key [
29 title: string # Name the key, so you will remember what it is used for
30 key: path # Path to the PUBLIC key
3031] {
31 # the paths are assumed to have already been linked from dotfiles
32 if $OS == "Windows" {
33 java (build-string X:/tools/ $name .java)
32 if ($key | path exists) {
33 echo (build-string "uploading ssh public key " (ansi gi) $key (ansi reset) " with title " (ansi gb) $title (ansi reset) " to GitHub.")
34 echo (char newline)
35 let encrypted_token_path = (build-string $nu.env.DOTFILES / tresor / 4cef0ce3-da3a-4f16-9412-2d094b4f7445)
36 let decrypted_token_path = (build-string $nu.env.DOTFILES / tresor / gh_token)
37 aes decrypt $encrypted_token_path $decrypted_token_path
38 let token = (open --raw $decrypted_token_path)
39 let key_content = (open --raw $key)
40 rm -f $decrypted_token_path
41 let result = (do -i { xh --bearer $token https://api.github.com/user/keys (build-string title = $title) (build-string key = $key_content) | from json})
42 if ($result | has-column? errors) {
43 let message = ($result | get message)
44 let url = ($result | get documentation_url)
45 let errors = ($result | get errors)
46 echo (build-string (ansi rb) $message (ansi reset) (char newline))
47 echo (char newline)
48 $errors | each {
49 let resource = ($it | get resource)
50 let code = ($it | get code)
51 let field = ($it | get field)
52 let message = ($it | get message)
53 echo (build-string (ansi ui) $resource : $code : $field ": " (ansi rb) $message (ansi reset) (char newline))
54 }
55 echo (build-string "Further information: " (ansi yi) $url (ansi reset) (char newline))
56 } {
57 let id = ($result | get id)
58 let key = ($result | get key)
59 let title = ($result | get title)
60 let created_at = ($result | get created_at)
61 echo (build-string "[" ID : $id "]" " key with title " (ansi gb) $title (ansi reset) " was created at " (ansi yi) $created_at (ansi reset) "." (char newline) )
62 echo (build-string (ansi wu) "PUBLIC SSH KEY:" (ansi reset))
63 echo (char newline)
64 echo ($key | ansi gradient --fgstart 0xaefe9f --fgend 0xfefefe)
65 echo (char newline)
66 }
3467 } {
35 java (build-string ~/.local/tools/ $name .java)
68 echo (build-string "key " (ansi rb) $key (ansi reset) " not found!")
69 echo (char newline)
3670 }
73# Shows git log in a pretty table
74def glog [
75 ...rest: string # Extra arguments to git log
76] {
77 git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n 25 $rest | lines | split column "»¦«" commit subject name email date | update date { get date | str to-datetime} | sort-by date
78}
3980def man [
4081 program: string
4182] {
42 if $OS == "Windows" {
83 if (sys).host.name == "Windows" {
4384 start (build-string https://man.cx/ $program)
4485 } {
4586 exec man $program
5596 start (build-string "https://duckduckgo.com/?q=" $query)
58# Browse and select files in the current directory with an interactive file viewer.
59def files [
60 ...rest # Arguments will be passed to fzf
99# Check whether table in pipeline has a column with given name
100def "has-column?" [
101 name: string # Name of the column to check for
61102] {
62 let options = ["--ansi", "--info", "inline"]
63 let layout = ["--height", "100%", "--layout", "reverse", "--border", "--preview-window", "up:1:noborder:66%"]
64 let color = ["--color", "fg:#adadad,fg+:#78aba9,bg:#333333,preview-bg:#222222,border:#547877"]
65 let preview = ["--preview", "bat --color=always --italic-text=always --decorations=never --line-range :300 {}"]
66 fzf $options $layout $color $preview $rest
103 pivot | any? Column0 == $name
69# Show or add to bugabingas TODO file.
70def todo [
71 --edit (-e) # Edit the todo file in $EDITOR
72 item?: string # New TODO item to append to TODO file
106# Prints out a list of stuff.
107# Appends a newline at the end.
108def print [
109 ...rest: any # list of stuff to echo out
73110] {
74 if ($edit | empty?) {
75 # How is one supposed to check the optional variable if it is not in scope, when not given?
76 #if $(= $item | empty?) {
77 glow $TODO_FILE
78 # } {
79 # appending a line to a file seems kind of sus in nushell right now... ask on discord about this?
80 # open $TODO_FILE | lines | append $(build-string "- " $item) | save $TODO_FILE
81 # }
82 } {
83 # Is this the nu way of running dynamic commands?
84 nu --commands (build-string $nu.env.EDITOR " " $TODO_FILE)
85 }
111 echo (build-string ($rest | flatten | into string | str collect) )
112 echo (char newline)

nushell/nu/config/zoxide.nu

Modified

+13 / −14 text lines

1# Code generated by zoxide. DO NOT EDIT.
2
13# =============================================================================
24#
35# Utility functions for zoxide.
68# Default prompt for Nushell.
79def __zoxide_prompt [] {
8 let git = $"(do -i {git rev-parse --abbrev-ref HEAD} | str trim)"
10 let git = $'(do -i {git rev-parse --abbrev-ref HEAD} | str trim)'
911 let git = (if (echo $git | str length) == 0 {
10 ""
12 ''
1113 } {
1214 build-string (char lparen) (ansi cb) $git (ansi reset) (char rparen)
1315 })
14 build-string (ansi gb) (pwd) (ansi reset) $git "> "
16 build-string (ansi gb) (pwd) (ansi reset) $git '> '
1719# =============================================================================
3436def __zoxide_z [...rest:string] {
3537 if (shells | where active == $true | get name) != filesystem {
3638 if (echo $rest | length) > 1 {
37 $"zoxide: can only jump directories on filesystem(char nl)"
39 $'zoxide: can only jump directories on filesystem(char nl)'
3840 } {
3941 cd (echo $rest)
4042 }
4345 if (echo $rest | length) <= 1 && ($arg0 == '-' || (echo $arg0 | path expand | path exists)) {
4446 cd $arg0
4547 } {
46 cd (zoxide query --exclude (pwd) -- $rest | str trim)
48 cd $'(zoxide query --exclude (pwd) -- $rest | str trim)'
4749 }
4850 }
5153# Jump to a directory using interactive search.
5254def __zoxide_zi [...rest:string] {
5355 if (shells | where active == $true | get name) != filesystem {
54 $"zoxide: can only jump directories on filesystem(char nl)"
56 $'zoxide: can only jump directories on filesystem(char nl)'
5557 } {
56 cd (zoxide query -i -- $rest | str trim)
58 cd $'(zoxide query -i -- $rest | str trim)'
5759 }
6870# =============================================================================
70# To initialize zoxide, first create a Nushell script:
72# To initialize zoxide, add this to your configuration (find it by running
73# `config path` in Nushell):
72# zoxide init nushell --hook prompt | save ~/.zoxide.nu
73#
74# Add this to your configuration (usually ~/.config/nu/config.toml):
75#
76# prompt = "__zoxide_hook;__zoxide_prompt"
77# startup = ["zoxide init nushell --hook prompt | save ~/.zoxide.nu", "source ~/.zoxide.nu"]
75# prompt = '__zoxide_hook;__zoxide_prompt'
76# startup = ['zoxide init nushell --hook prompt | save ~/.zoxide.nu', 'source ~/.zoxide.nu']
7978# You can replace __zoxide_prompt with a custom prompt.

tools/aes.java

Modified

+2 / −4 text lines

1313import javax.crypto.spec.*;
1515class aes {
1716 enum Command { ENCRYPT, DECRYPT };
1917 static Cipher AES_GCM_PKCS5;
2018 static byte[] SALT = new byte[] { 116, 104, 101, 32, 109, 111, 111, 110, 32, 105, 115, 32, 104, 105, 100, 100, 101, 110, 32, 105, 110, 32, 112, 108, 97, 105, 110, 32, 118, 105, 101, 119 };
2119 static SecureRandom RANDOM = new SecureRandom();
115113 break;
116114 }
117115 }
119116 throw exit();
120117 }
155152 var aes_bytes_count = AES_GCM_PKCS5.update(read_buffer, 0, read_bytes_count, aes_buffer);
156153 output.write(aes_buffer, 0, aes_bytes_count);
157154 }
158 //FIXME: the java impl of GCM seems to buffer the whole data in memory and only releasing it on doFinal. yuck!
155 // the java impl of GCM seems to buffer the whole data in memory and only releasing it on doFinal. yuck!
156 // there is not much i can do about this other than to wait for JDK patches.
159157 //TODO: in the case of AES GCM the final byte block is the authentication tag.
160158 //as such it should porbably NOT be written to the output file.
161159 //or is this assumption wrong?