3

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?

deshmukh
  • 4,061

2 Answers2

4

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).

muru
  • 197,895
  • 55
  • 485
  • 740
0

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'
dessert
  • 39,982