From 406b019fecee79d7551cf771ae5787aa89ee13e8 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:37:50 -0500 Subject: [PATCH] Update --- config.nu | 122 ++++++++++++++++++++++++++++------------------ env.nu | 22 +++++++-- modules/debian.nu | 14 ++++++ modules/redhat.nu | 6 +++ 4 files changed, 112 insertions(+), 52 deletions(-) create mode 100644 modules/debian.nu create mode 100644 modules/redhat.nu diff --git a/config.nu b/config.nu index 32c91d2..d2af433 100644 --- a/config.nu +++ b/config.nu @@ -7,6 +7,11 @@ def 'is-installed' [ app: string ] { ((which $app | length) > 0) } +# Global vars and consts +let hostn = (sys | get host.hostname) +const MODDIR = ($nu.default-config-dir | path join "modules") + + # # MODULES # @@ -20,13 +25,39 @@ use ~/.config/nushell/modules/ultimate-extractor.nu extract # ssh use ~/.config/nushell/modules/ssh.nu +# Source distro-specific modules +const DEBIAN_CONF = ($MODDIR | path join "debian.nu") +const REDHAT_CONF = ($MODDIR | path join "redhat.nu") +const DISTRO_CONFIG = if ("/etc/debian_version" | path exists) { + $DEBIAN_CONF +} else if ("/etc/redhat-release" | path exists) { + $REDHAT_CONF +} else { + $nu.env-path +} +source $DISTRO_CONFIG # # ALIASES / CUSTOM COMMANDS # +# Custom commands for Doom Emacs +def doomdoc [] { ~/.config/emacs/bin/doom doctor } +def dsync [] { ~/.config/emacs/bin/doom sync } +def dclean [] { ~/.config/emacs/bin/doom clean } +def dcomp [] { ~/.config/emacs/bin/doom compile } +def dpurge [] { ~/.config/emacs/bin/doom purge } +def denv [] { ~/.config/emacs/bin/doom env } +def dupgrade [] { ~/.config/emacs/bin/doom upgrade } + # weather -export alias weather = get_weather +export alias weath = get_weather + +# firewalld aliases +export alias fw = sudo firewall-cmd +export alias fwp = sudo firewall-cmd --permanent +export alias fwr = sudo firewall-cmd --reload +export alias fwrp = sudo firewall-cmd --runtime-to-permanent # Git aliases export alias ga = git add @@ -47,54 +78,30 @@ 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 } -def dclean [] { ~/.config/emacs/bin/doom clean } -def dcomp [] { ~/.config/emacs/bin/doom compile } -def dpurge [] { ~/.config/emacs/bin/doom purge } -def denv [] { ~/.config/emacs/bin/doom env } -def dupgrade [] { ~/.config/emacs/bin/doom upgrade } - -# firewalld -export alias fw = sudo firewall-cmd -export alias fwp = sudo firewall-cmd --permanent -export alias fwr = sudo firewall-cmd --reload -export alias fwrp = sudo firewall-cmd --runtime-to-permanent - -# Execute bash on host (atomic desktop) -export alias hostexec = distrobox-host-exec bash - -# APT -export alias acs = sudo apt-cache search -export alias acp = sudo apt-cache policy -export alias afs = sudo apt-file search -export alias afu = sudo apt-file update -export alias aac = sudo apt autoclean -export alias agc = sudo apt clean -export alias agi = sudo apt install -export alias agli = sudo apt list --installed -export alias agp = sudo apt purge -export alias agr = sudo apt remove -export alias agu = sudo apt update -export alias agud = sudo apt update and sudo apt dist-upgrade -export alias agar = sudo apt autoremove - -# DNF -export alias dnfc = sudo dnf clean all -export alias dnfi = sudo dnf install -export alias dnfu = sudo dnf update -export alias dnfr = sudo dnf remove -export alias dnfs = sudo dnf search +# Copy trimmed GPG fingerprint to clipboard +def gpgfpr [] { + gpg -K --with-colons + | jc --gpg + | from json + | get 1.user_id + | xclip -sel clipboard +} # Copy SSH public key to clipboard -def pubkey [] { open --raw ~/.ssh/id_ed25519.pub | str trim | xclip -selection clipboard } +def pubkey [] { + open --raw ~/.ssh/id_ed25519.pub + | str trim + | xclip -selection clipboard +} # Get public ip info def pubip [] { curl --silent ipinfo.io | from json } # Get Mullvad info -def amimullvad [] { curl -sSL https://am.i.mullvad.net/json | from json } +def amimullvad [] { + curl -sSL https://am.i.mullvad.net/json + | from json +} # Uptime info def upt [] { jc uptime | from json } @@ -103,16 +110,28 @@ def upt [] { jc uptime | from json } def dfj [] { jc df | from json } # /etc/fstab info -def etc-fstab [] { open --raw /etc/fstab | jc --fstab | from json } +def etc-fstab [] { + open --raw /etc/fstab + | jc --fstab + | from json +} # memory free info def memfree [] { jc free | from json } # /etc/group -def etc-group [] { open --raw /etc/group | jc --group | from json } +def etc-group [] { + open --raw /etc/group + | jc --group + | from json +} # /etc/passwd -def etc-passwd [] { open --raw /etc/passwd | jc --passwd | from json } +def etc-passwd [] { + open --raw /etc/passwd + | jc --passwd + | from json +} # Network connections def netcons [] { jc lsof -i | from json } @@ -121,7 +140,11 @@ def netcons [] { jc lsof -i | from json } def tulp [] { jc ss -tulp | from json } # Open ports -def openports [] { sudo jc lsof -i | from json | find "LISTEN" } +def openports [] { + sudo jc lsof -i + | from json + | find "LISTEN" +} # List sockets in use def lsock [] { sudo jc lsof -nP | from json } @@ -142,7 +165,10 @@ def --env mkd [path] { mkdir $path; cd $path } def pids [cmd] { ps | where name == "$cmd" } # Get time in specific time zone -def whattimein [string] { date now | date to-timezone $string } +def whattimein [string] { + date now + | date to-timezone $string +} # cd to home and clear screen def --env rsrc [] { cd $env.HOME; clear } @@ -198,7 +224,7 @@ def yaml2json [filename: path] { } # Download a file with httpie -def htdl [url: string] { +def httpie [url: string] { ^http -d $url } diff --git a/env.nu b/env.nu index 40c16fd..52e3337 100644 --- a/env.nu +++ b/env.nu @@ -51,7 +51,7 @@ def is-container [] { } def create_user_host [] { - let user_host = (ansi red) + (whoami) + (ansi reset) + '@' + (ansi blue) + (sys | get host.hostname) + (ansi reset) + let user_host = (ansi red) + (whoami) + (ansi reset) + '@' + (ansi "#89b4fa") + (sys | get host.hostname) + (ansi reset) let container_segment = (ansi green_bold) + "⬢ " + (ansi reset) let user_host_segment = (if (is-container) { ($container_segment + $user_host) | str join } else { $user_host }) @@ -99,7 +99,21 @@ $env.NU_PLUGIN_DIRS = [ ] # Doom Emacs -$env.DOOMDIR = ($env.HOME | path join 'sync/doom') +$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') +# Various paths +$env.CARGO_HOME = ($env.HOME | path join ".cargo") + +# PATH +use std "path add" +path add ($env.CARGO_HOME | path join "bin") +path add ($env.HOME | path join "go" "bin") +path add ($env.HOME | path join "bin") +path add ($env.HOME | path join ".local" "bin") +path add /usr/bin +path add /usr/sbin +path add /usr/local/bin +$env.PATH = ($env.PATH | uniq) + +# LS_COLORS using vivid +$env.LS_COLORS = (vivid generate catppuccin-mocha | str trim) diff --git a/modules/debian.nu b/modules/debian.nu new file mode 100644 index 0000000..91a8b58 --- /dev/null +++ b/modules/debian.nu @@ -0,0 +1,14 @@ +# Aliases for APT +export alias acs = sudo apt-cache search +export alias acp = sudo apt-cache policy +export alias afs = sudo apt-file search +export alias afu = sudo apt-file update +export alias aac = sudo apt autoclean +export alias agc = sudo apt clean +export alias agi = sudo apt install +export alias agli = sudo apt list --installed +export alias agp = sudo apt purge +export alias agr = sudo apt remove +export alias agu = sudo apt update +export alias agud = sudo apt update and sudo apt dist-upgrade +export alias agar = sudo apt autoremove diff --git a/modules/redhat.nu b/modules/redhat.nu new file mode 100644 index 0000000..0f8104f --- /dev/null +++ b/modules/redhat.nu @@ -0,0 +1,6 @@ +# Aliases for DNF +export alias dnfc = sudo dnf clean all +export alias dnfi = sudo dnf install +export alias dnfu = sudo dnf update +export alias dnfr = sudo dnf remove +export alias dnfs = sudo dnf search