at main 5.1 kB view raw
1# Nushell Config File 2 3# Command existence checker function 4def 'is-installed' [ app: string ] { 5 ((which $app | length) > 0) 6} 7 8# 9# MODULES 10# 11 12# ultimate-extractor 13use ~/.config/nushell/modules/ultimate-extractor.nu extract 14 15# ssh 16use ~/.config/nushell/modules/ssh.nu 17 18# 19# ALIASES / CUSTOM COMMANDS 20# 21 22# firewalld aliases 23export alias fw = sudo firewall-cmd 24export alias fwp = sudo firewall-cmd --permanent 25export alias fwr = sudo firewall-cmd --reload 26export alias fwrp = sudo firewall-cmd --runtime-to-permanent 27 28# Git aliases 29export alias ga = git add 30export alias gcl = git clone 31export alias gcmsg = git commit -m 32export alias gd = git diff 33export alias gl = git pull 34export alias gp = git push 35export alias gr = git remote 36export alias grbi = git rebase -i 37export alias grm = git rm 38export alias grv = git remote -v 39export alias gst = git status 40 41# ls's 42export alias la = ls -a 43export alias ll = ls -l 44export alias lal = ls -al 45export alias lse = ^ls -lZ 46 47# Copy trimmed GPG fingerprint to clipboard 48def gpgfpr [] { 49 gpg -K --with-colons 50 | jc --gpg 51 | from json 52 | get 1.user_id 53 | xclip -sel clipboard 54} 55 56# Copy SSH public key to clipboard 57def pubkey [] { 58 open --raw ~/.ssh/id_ed25519.pub 59 | str trim 60 | xclip -selection clipboard 61} 62 63# Get public ip info 64def pubip [] { curl --silent ipinfo.io | from json } 65 66# Get Mullvad info 67def amimullvad [] { 68 curl -sSL https://am.i.mullvad.net/json 69 | from json 70} 71 72# Uptime info 73def upt [] { jc uptime | from json } 74 75# df info 76def dfj [] { jc df | from json } 77 78# /etc/fstab info 79def etc-fstab [] { 80 open --raw /etc/fstab 81 | jc --fstab 82 | from json 83} 84 85# memory free info 86def memfree [] { jc free | from json } 87 88# /etc/group 89def etc-group [] { 90 open --raw /etc/group 91 | jc --group 92 | from json 93} 94 95# /etc/passwd 96def etc-passwd [] { 97 open --raw /etc/passwd 98 | jc --passwd 99 | from json 100} 101 102# Network connections 103def netcons [] { jc lsof -i | from json } 104 105# Ports 106def tulp [] { jc ss -tulp | from json } 107 108# Open ports 109def openports [] { 110 sudo jc lsof -i 111 | from json 112 | find "LISTEN" 113} 114 115# List sockets in use 116def lsock [] { sudo jc lsof -nP | from json } 117 118# List UDP sockets in use 119def lsocku [] { sudo jc lsof -nP | from json | find "UDP" } 120 121# List TCP sockets in use 122def lsockt [] { sudo jc lsof -nP | from json | find "TCP" } 123 124# Print timestamp as %FT%T%:z 125def tstampz [] { date now | format date "%FT%T%:z" } 126 127# Create new directory and enter it 128def --env mkd [path] { mkdir $path; cd $path } 129 130# Display pid info of command 131def pids [cmd] { ps | where name == $cmd } 132 133# Get time in specific time zone 134def whattimein [string] { 135 date now 136 | date to-timezone $string 137} 138 139# cd to home and clear screen 140def --env rsrc [] { cd $env.HOME; clear } 141 142# extract 143def x [filename: path] { extract $filename } 144 145# Convert filename to given case 146# Ex. caseify camel hello_world.txt 147# => helloWorld.txt 148# Based on https://github.com/nushell/nu_scripts/blob/main/sourced/cool-oneliners/file_convert_naming_case.nu 149def caseify [case: string, filename: path] { 150 let ext = (echo $filename | path parse | get extension) 151 let cur_stem = (echo $filename | path parse | get stem) 152 let new_name = match $case { 153 "camel" => (((echo $cur_stem | str camel-case) + "." + $ext) | str join), 154 "kebab" => (((echo $cur_stem | str kebab-case) + "." + $ext) | str join), 155 "lower" => (((echo $cur_stem | str downcase) + "." + $ext) | str join), 156 "pascal" => (((echo $cur_stem | str pascal-case) + "." + $ext) | str join), 157 "screamsnake" => (((echo $cur_stem | str screaming-snake-case) + "." + $ext) | str join), 158 "snake" => (((echo $cur_stem | str snake-case) + "." + $ext) | str join), 159 _ => "Invalid case option" 160 } 161 mv $filename $new_name 162} 163 164# Select a host to SSH into 165def nussh [] { 166 let ssh_host = (ssh ssh-list | get Host | input list $"\n(ansi red)Which host to SSH into?(ansi reset)") 167 if ($ssh_host | describe) != "string" { 168 echo "Operation cancelled" 169 return 170 } 171 autossh -M 0 $ssh_host 172} 173 174# Select an open source license and save to LICENSE in current working directory 175def nulicense [] { 176 let licenses = (http get https://api.github.com/licenses) 177 let license_name = ($licenses | get name | input list $"(ansi yellow)Choose an open source license:(ansi reset)") 178 if ($license_name | describe) != "string" { 179 echo "Operation cancelled" 180 return 181 } 182 let license_body = (http get ($licenses | where name == $license_name).url.0).body 183 $license_body | save --raw -f LICENSE 184} 185 186# Convert YAML to JSON 187def yaml2json [filename: path] { 188 let stem = (echo $filename | path parse | get stem) 189 open --raw $filename | from yaml | to json | save --raw ($stem + ".json" | str join) 190} 191 192# Download a file with httpie 193def httpie [url: string] { 194 ^http -d $url 195} 196 197$env.config = { 198 rm: { 199 always_trash: true 200 } 201 202 table: { 203 show_empty: false 204 } 205 206 keybindings: [ 207 { 208 name: nussh 209 modifier: alt 210 keycode: char_s 211 mode: [emacs vi_normal vi_insert] 212 event: { send: executehostcommand cmd: nussh } 213 } 214 ] 215}