Global Aliases

Global aliases - Do not have to be at the beginning of the command line.

Typical use is:

alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'
alias -g L="| less"
alias -g M="| most"
alias -g B="&|"
alias -g HL="--help"
alias -g LL="2>&1 | less"
alias -g CA="2>&1 | cat -A"
alias -g NE="2> /dev/null"
alias -g NUL="> /dev/null 2>&1"

Global aliases can be probably evil!

They don't expand immediately and you might one day want an argument that matches one. It is a good idea to choose something you're unlikely to need. Here's some more examples:

alias -g '¬A'='**/*(.)'
alias -g '¬/'='**/*(/)'
alias -g '¬O'='*(U)'

The ¬ character appears on a UK keyboard and has no other uses so is a good choice. A more general good option is ] as it will rarely be needed without a preceding [ and you don't need to press shift to type it. You might also use !, ~, ^ or = as a suffix as they tend to only be special as a prefix.

In the example above, ¬A will expand to all plain files below $PWD, ¬/ all directories and ¬O all files in $PWD only, owned by you. (If you don't have setopt GLOB_DOTS and want to include dotfiles in these, you might want to tuck on a D inside the ellipsis too.)

If you have a symlink from /cdrom to /media/cdrom (or similar), the following global alias allows things like ls /cdrom to do what you intend.

alias -g '/cdrom'='/cdrom/.'

An alternative to global aliases is to use bindkey -s. This expands the string as you type so it doesn't need to be in its own word. You may need to tweak the KEYTIMEOUT variable if you can't type the characters fas enough. For example:

bindkey -s '\\p' '(../)##'

This can be useful to git users:

alias -g gitnulltree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
examples/aliasglobal.txt · Last modified: 2015/03/24 17:25 by remove-spam-mckael