In the case of gc
(which I assume is defined as alias gc='git commit -v'
in the git plugin of oh-my-zsh) zsh
internally substitutes the alias (gc
) with the actual command (git commit -v
) before looking for trying for completions. This works for every alias (unless the shell option COMPLETE_ALIASES
is set, which would allow to set separate completions for aliases).
As for what you want to do: Seing that -w
is actually a function and not an alias, you indeed would have to write your own completion. But there is a much simpler way to go about it: Static named directories.
Named directories are usually just the home directories of the users on the system. The most commonly known is probably ~
for the home directory of the current user. Other users directories are named ~USERNAME
. You can also define your own static named directories. There are two ways to do this:
- Use
hash -d
to explicitly define a name, similar to an alias:
hash -d w=~/workspace
- Implicitly define it by defining a string shell parameter whose value begins with an
/
(this also means you cannot use ~
as shortcut for your home directory)
w="${HOME}/workspace"
In both cases you now can use ~w
to reference your workspace, in the second case you can also use $w
(for example for use in quoted strings). Typing cd ~w/a-repo
will get you to ~/workspace/a-repo
. Tab-completion works like it would with any other path, so pressing ~w/a<Tab>
will present you ~w/a-repo
as completion.
Additionally, if you set the shell option AUTO_CD (setopt AUTO_CD
), you can switch into a directory just by typing the path (or directory name) without the need for cd
.
% w="/tmp"
% cd ~w
% pwd
/tmp
% mkdir 1 2 3
% setopt AUTO_CD
% ~w/<TAB>
1 2 3
% ~w/1
% pwd
/tmp/1