diff --git a/config.nu b/config.nu index 057b8a7..32c91d2 100644 --- a/config.nu +++ b/config.nu @@ -7,6 +7,27 @@ def 'is-installed' [ app: string ] { ((which $app | length) > 0) } +# +# MODULES +# + +# weather +use ~/.config/nushell/modules/get-weather.nu get_weather + +# ultimate-extractor +use ~/.config/nushell/modules/ultimate-extractor.nu extract + +# ssh +use ~/.config/nushell/modules/ssh.nu + + +# +# ALIASES / CUSTOM COMMANDS +# + +# weather +export alias weather = get_weather + # Git aliases export alias ga = git add export alias gcl = git clone @@ -20,6 +41,12 @@ export alias grm = git rm export alias grv = git remote -v export alias gst = git status +# ls's +export alias la = ls -a +export alias ll = ls -l +export alias lal = ls -al +export alias lse = ^ls -lZ + # Doom Emacs def doomdoc [] { ~/.config/emacs/bin/doom doctor } def dsync [] { ~/.config/emacs/bin/doom sync } @@ -38,7 +65,7 @@ export alias fwrp = sudo firewall-cmd --runtime-to-permanent # Execute bash on host (atomic desktop) export alias hostexec = distrobox-host-exec bash -# Aliases for APT +# APT export alias acs = sudo apt-cache search export alias acp = sudo apt-cache policy export alias afs = sudo apt-file search @@ -53,7 +80,7 @@ export alias agu = sudo apt update export alias agud = sudo apt update and sudo apt dist-upgrade export alias agar = sudo apt autoremove -# Aliases for DNF +# DNF export alias dnfc = sudo dnf clean all export alias dnfi = sudo dnf install export alias dnfu = sudo dnf update @@ -67,19 +94,19 @@ def pubkey [] { open --raw ~/.ssh/id_ed25519.pub | str trim | xclip -selection c def pubip [] { curl --silent ipinfo.io | from json } # Get Mullvad info -def amimulvad [] { curl -sSL https://am.i.mullvad/json | from json } +def amimullvad [] { curl -sSL https://am.i.mullvad.net/json | from json } # Uptime info -def upt [] { uptime | jc --uptime | from json } +def upt [] { jc uptime | from json } # df info -def dfj [] { df | jc --df | from json } +def dfj [] { jc df | from json } # /etc/fstab info def etc-fstab [] { open --raw /etc/fstab | jc --fstab | from json } # memory free info -def memfree [] { free | jc --free | from json } +def memfree [] { jc free | from json } # /etc/group def etc-group [] { open --raw /etc/group | jc --group | from json } @@ -88,22 +115,22 @@ def etc-group [] { open --raw /etc/group | jc --group | from json } def etc-passwd [] { open --raw /etc/passwd | jc --passwd | from json } # Network connections -def netcons [] { lsof -i | jc --lsof | from json } +def netcons [] { jc lsof -i | from json } # Ports -def tulp [] { ss -tulp | jc --ss | from json } +def tulp [] { jc ss -tulp | from json } # Open ports -def openports [] { sudo lsof -i | jc --lsof | from json | find "LISTEN" } +def openports [] { sudo jc lsof -i | from json | find "LISTEN" } # List sockets in use -def lsock [] { sudo lsof -i P | jc --lsof | from json } +def lsock [] { sudo jc lsof -nP | from json } # List UDP sockets in use -def lsocku [] { sudo lsof -nP | jc --lsof | from json | find "UDP" } +def lsocku [] { sudo jc lsof -nP | from json | find "UDP" } # List TCP sockets in use -def lsockt [] { sudo lsof -nP | jc --lsof | from json | find "TCP" } +def lsockt [] { sudo jc lsof -nP | from json | find "TCP" } # Print timestamp as %FT%T%:z def tstampz [] { date now | format date "%FT%T%:z" } @@ -120,6 +147,9 @@ def whattimein [string] { date now | date to-timezone $string } # cd to home and clear screen def --env rsrc [] { cd $env.HOME; clear } +# extract +def x [filename: path] { extract $filename } + # Convert filename to given case # Ex. caseify camel hello_world.txt # => helloWorld.txt @@ -139,26 +169,17 @@ def caseify [case: string, filename: path] { mv $filename $new_name } -# weather -use ~/.config/nushell/modules/get-weather.nu get_weather -export alias weather = get_weather - -# ultimate-extractor -use ~/.config/nushell/modules/ultimate-extractor.nu extract -def x [path] { extract $path } - -# ssh -use ~/.config/nushell/modules/ssh.nu - +# Select a host to SSH into def nussh [] { let ssh_host = (ssh ssh-list | get Host | input list $"(ansi yellow)Which host to SSH into?(ansi reset)") if ($ssh_host | describe) != "string" { echo "Operation cancelled" return } - ssh $ssh_host + autossh -M 0 $ssh_host } +# Select an open source license and save to LICENSE in current working directory def nulicense [] { let licenses = (http get https://api.github.com/licenses) let license_name = ($licenses | get name | input list $"(ansi yellow)Choose an open source license:(ansi reset)") @@ -170,11 +191,17 @@ def nulicense [] { $license_body | save --raw -f LICENSE } +# Convert YAML to JSON def yaml2json [filename: path] { let stem = (echo $filename | path parse | get stem) open --raw $filename | from yaml | to json | save --raw ($stem + ".json" | str join) } +# Download a file with httpie +def htdl [url: string] { + ^http -d $url +} + $env.config = { rm: { always_trash: true diff --git a/env.nu b/env.nu index 41924a7..5d7b02b 100644 --- a/env.nu +++ b/env.nu @@ -98,7 +98,8 @@ $env.NU_PLUGIN_DIRS = [ ($nu.default-config-dir | path join 'plugins') # add /plugins ] +# Doom Emacs +$env.DOOMDIR = ($env.HOME | path join 'sync/doom') + # To add entries to PATH (on Windows you might use Path), you can use the following pattern: # $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path') -let gopath = ($env.HOME + '/go/bin' | str join) -$env.PATH = ($env.PATH | split row (char esep) | prepend $gopath)