From dc71f747da6d16f52f288ec296de2c0d39e51a26 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 29 Nov 2025 15:58:51 +0100 Subject: [PATCH] nu: Copy basic sh aliases Held back a little by the issue that you can't really set aliases conditionally (yet?) in nushell, which is kind of fundamental to my zsh/sh alias setup. If a program exists, we add some nice aliases -- if not, we simply degrade gracefully and don't add anything. PR to track issue: https://github.com/nushell/nushell/issues/5068 --- sh/.config/sh/alias | 5 +- terminal/.config/nushell/autoload/alias.nu | 59 ++++++++++++++++++++++ terminal/.config/nushell/config.nu | 14 ----- 3 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 terminal/.config/nushell/autoload/alias.nu diff --git a/sh/.config/sh/alias b/sh/.config/sh/alias index 21a296e..0fa829a 100644 --- a/sh/.config/sh/alias +++ b/sh/.config/sh/alias @@ -8,7 +8,10 @@ exist() { type "$1" >/dev/null 2>&1; } unalias -a if alias v >/dev/null 2>&1; then - if exist vim; then + if exist nvim; then + alias v="nvim" + alias vim="vi" + elif exist vim; then alias v="vim" else alias v="vi" diff --git a/terminal/.config/nushell/autoload/alias.nu b/terminal/.config/nushell/autoload/alias.nu new file mode 100644 index 0000000..1da6727 --- /dev/null +++ b/terminal/.config/nushell/autoload/alias.nu @@ -0,0 +1,59 @@ +alias ":q" = exit # quit nushell + +def --wrapped vim [...rest] { + let cmds = which nvim vim vi | where path != "" + if ($cmds | is-empty) { + error make {msg: "No vi-like binary found."} + } + let c = $cmds | first | get path + ^$c ...$rest +} +alias v = vim # start ideal vim (nvim/vim/vi) + +alias l = ls # list files +alias L = ls --all # list files including hidden +alias ll = ls **/* # list files recursively +alias LL = ls --all **/* # list files recursively including hidden +# can additionally support `eza` output when +# PR https://github.com/eza-community/eza/issues/768 lands + +# make directory +alias md = mkdir +# make and enter directory +def --env mcd [path: path] { + mkdir $path + cd $path +} + +alias cl = clear # clear screen + +# FIXME: cll functionality seems hard to accomplish? + +alias myip = http get icanhazip.com # return current ip + +def --env --wrapped vmm [...rest] { + if (which vifm | is-not-empty) { + let rest = $rest | each {path expand} + vifm ...$rest $env.PWD + } else { + print "No vifm executable found." + } +} +alias vm = vifm + +def --wrapped iv [...rest] { + let cmds = which vimiv imv nsxiv sxiv feh | where path != "" + if ($cmds | is-empty) { + error make {msg: "No image viewer binary found."} + } + let c = $cmds | first | get path + ^$c ...$rest +} + +alias db = distrobox + +alias sc = sc-im + +# job control +# TODO: requires minimum nushell: 0.103 for job control, how to check for it? +alias fg = job unfreeze diff --git a/terminal/.config/nushell/config.nu b/terminal/.config/nushell/config.nu index 36173e5..d483f7a 100644 --- a/terminal/.config/nushell/config.nu +++ b/terminal/.config/nushell/config.nu @@ -146,17 +146,3 @@ $env.config.keybindings = [ } } ] - -alias l = ls -alias cl = clear - -alias md = mkdir -def --env mcd [path: path] { - mkdir $path - cd $path -} - -alias v = nvim - -# requires minimum nushell: 0.103 for job control -alias fg = job unfreeze