1 +# This is an initial script for nushell
2 +# It is expected that it is sourced in the `config.toml`:
3 +# `startup = ["source ~/.config/nushell/nurc"]`
6 +let-env NURC = (build-string (pwd) /nurc)
7 +let-env DOTFILES = ((build-string (pwd) /..) | path expand)
15 +alias todo = glow (build-string $nu.env.DOTFILES / TODO.md)
16 +alias nurc = nvim $nu.env.NURC
18 +# CUSTOM LITTLE JAVA COMMANDS
19 +alias sha = java (build-string $nu.env.DOTFILES /tools/ sha.java)
20 +alias aes = java (build-string $nu.env.DOTFILES /tools/ aes.java)
21 +alias uuid = java (build-string $nu.env.DOTFILES /tools/ random_uuid.java)
22 +alias download = java (build-string $nu.env.DOTFILES /tools/ download.java)
23 +alias download_jar = java (build-string $nu.env.DOTFILES /tools/ download_jar.java)
27 +# Uploads a PUBLIC ssh key to GitHub.
28 +# Will prompt for the AES encryption password of my dotfiles.
29 +def github-upload-key [
30 + title: string # Name the key, so you will remember what it is used for
31 + key: path # Path to the PUBLIC key
33 + if ($key | path exists) {
34 + echo (build-string "uploading ssh public key " (ansi gi) $key (ansi reset) " with title " (ansi gb) $title (ansi reset) " to GitHub.")
36 + let encrypted_token_path = (build-string $nu.env.DOTFILES / tresor / 4cef0ce3-da3a-4f16-9412-2d094b4f7445)
37 + let decrypted_token_path = (build-string $nu.env.DOTFILES / tresor / gh_token)
38 + aes decrypt $encrypted_token_path $decrypted_token_path
39 + let token = (open --raw $decrypted_token_path)
40 + let key_content = (open --raw $key)
41 + rm -f $decrypted_token_path
42 + let result = (do -i { xh --bearer $token https://api.github.com/user/keys (build-string title = $title) (build-string key = $key_content) | from json})
43 + if ($result | has-column? errors) {
44 + let message = ($result | get message)
45 + let url = ($result | get documentation_url)
46 + let errors = ($result | get errors)
47 + echo (build-string (ansi rb) $message (ansi reset) (char newline))
50 + let resource = ($it | get resource)
51 + let code = ($it | get code)
52 + let field = ($it | get field)
53 + let message = ($it | get message)
54 + echo (build-string (ansi ui) $resource : $code : $field ": " (ansi rb) $message (ansi reset) (char newline))
56 + echo (build-string "Further information: " (ansi yi) $url (ansi reset) (char newline))
58 + let id = ($result | get id)
59 + let key = ($result | get key)
60 + let title = ($result | get title)
61 + let created_at = ($result | get created_at)
62 + echo (build-string "[" ID : $id "]" " key with title " (ansi gb) $title (ansi reset) " was created at " (ansi yi) $created_at (ansi reset) "." (char newline) )
63 + echo (build-string (ansi wu) "PUBLIC SSH KEY:" (ansi reset))
65 + echo ($key | ansi gradient --fgstart 0xaefe9f --fgend 0xfefefe)
69 + echo (build-string "key " (ansi rb) $key (ansi reset) " not found!")
74 +# Shows git log in a pretty table
76 + ...rest: string # Extra arguments to git log
78 + 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
84 + if (sys).host.name == "Windows" {
85 + start (build-string https://man.cx/ $program)
91 +# Search the given query on the web with the default browser in DuckDuckGo.
93 + query:string # The search query
95 + # There seems to be an issue with the nu start command on windows: It does not handle URLs
96 + # Using windows command for now:
97 + start (build-string "https://duckduckgo.com/?q=" $query)
100 +# Check whether table in pipeline has a column with given name
102 + name: string # Name of the column to check for
104 + pivot | any? Column0 == $name
107 +# Prints out a list of stuff.
108 +# Appends a newline at the end.
110 + ...rest: any # list of stuff to echo out
112 + echo (build-string ($rest | flatten | into string | str collect) )
113 + echo (char newline)