Here is a simple thing I want to achieve. In the later part of a command, I want to use an abbreviation.
Say, I want to ls ~/Documents
but I just enter ls Docs
and it expands 'Docs' to '~/Documents'
How do I achieve it?
You can use "global" aliases in zsh:
alias -g Docs=~/Documents
Then ls Docs
will act like ls ~/Documents
.
Global aliases expand any word in a command line, not just the first, so any use of Docs
as an argument will be affected (unless quoted).
Define your abbreviation as a variable like
Docs="~/Documents"
and call it like so:
ls $Docs
Despite that's not what you want it's worth mentioning: A full command including options and arguments can be abbreviated using alias
, e.g.
alias 'Docs'='ls -l ~/Documents'