Conditional abbreviations #158
|
Thank you for the amazing plugin, and it works really well. Just wondering if its possible to add certain abbreviations only if the command exists. For example, this is what I have in my aliases file if [[ $(command -v eza) ]]; then
alias ls='eza -I "*pyc*" $eza_params'
alias lsa='ls --all'
...
fiHowever, when I import these aliases into abbreviations, this logic isn't respected automatically (which is acceptable and not a big deal). So is it possible to add such |
Replies: 1 comment 3 replies
|
Interesting question! Three solutions come to mind: Put the condition in the abbreviated command itself (wrapping the % abbr ls='command -v eza && { eza -I "*pyc*" $eza_params } || ls'Or use the standard command as a fallback ( % abbr ls='eza -I "*pyc*" $eza_params 2>/dev/null || ls'Or conditionally add # .zshrc
# load zsh-abbr and then
if …; then
# edit: this is what I said originally
# abbr -S …
# but in retrospect (see henrebotha's response) this is probably preferable
abbr …
fi |
Interesting question!
Three solutions come to mind:
Put the condition in the abbreviated command itself (wrapping the
ifcondition in{}prevents its exit code from affecting whether theelseis reached).% abbr ls='command -v eza && { eza -I "*pyc*" $eza_params } || ls'Or use the standard command as a fallback (
2>/dev/nullprevents the "zsh: command not found" output from showing in your terminal)% abbr ls='eza -I "*pyc*" $eza_params 2>/dev/null || ls'Or conditionally add
session abbreviationsedit: abbreviations when the shell starts: