diff options
| author | 2026-01-26 21:10:36 +0100 | |
|---|---|---|
| committer | 2026-01-26 21:10:36 +0100 | |
| commit | 4c2a9cdea49191f649af1be8f75ae33696ad5c47 (patch) | |
| tree | a8e13bdc9dcc65fb11acc2affc61fba94428b930 | |
| parent | zsh/tt: put the -f back (diff) | |
zsh: add and migrate to xfirstcmd
Basically the various forms for the multiple utility checks were
annoying me. This is nicer, even if the =$cmd looks a bit jank.
| -rw-r--r-- | dot_config/zsh/functions/xfirstcmd | 11 | ||||
| -rw-r--r-- | dot_config/zsh/zshrc | 10 |
2 files changed, 18 insertions, 3 deletions
diff --git a/dot_config/zsh/functions/xfirstcmd b/dot_config/zsh/functions/xfirstcmd new file mode 100644 index 0000000..53f0151 --- /dev/null +++ b/dot_config/zsh/functions/xfirstcmd @@ -0,0 +1,11 @@ +# -*- mode: sh -*- +# vim: ft=zsh + +local cmd +for cmd { + if [[ -x =$cmd ]] { + echo $cmd + return 0 + } +} +return 1 diff --git a/dot_config/zsh/zshrc b/dot_config/zsh/zshrc index 0b56623..b0428f8 100644 --- a/dot_config/zsh/zshrc +++ b/dot_config/zsh/zshrc @@ -15,6 +15,8 @@ bindkey '^x^e' edit-command-line bindkey '^[s' elevate-cmd ### Functions, Aliases +autoload -Uz xfirstcmd + ## Command replacements [[ -x =bat ]] && alias cat=bat c='bat -pp' [[ -x =bfs ]] && alias find=bfs @@ -22,9 +24,11 @@ bindkey '^[s' elevate-cmd [[ -x =colordiff ]] && alias diff=colordiff dif='colordiff -u' [[ -x =jaq ]] && alias jq=jaq [[ -x =podman ]] && alias docker=podman -if [[ -x =eza ]] { alias ls=eza tree='ls -T' -} elif [[ -x =exa ]] { alias ls=exa tree='ls -T' -} elif [[ -x =lsd ]] { alias ls=lsd lh='ls --hyperlink=auto' tree='lh --tree' } +case $(xfirstcmd eza exa lsd) { + eza) alias ls=eza tree='ls -T' ;; + exa) alias ls=exa tree='ls -T' ;; + lsd) alias ls=lsd lh='ls --hyperlink=auto' tree='lh --tree' ;; +} alias l='ls -l' ll='ls -l' la='ls -a' lla='ls -la' [[ -x =ugrep ]] && alias grep='ugrep -G -.' xdump='ugrep -X ""' alias uq='ug -Q' ux='ug -UX' uz='ug -z' g='ug -G -.' |
