Custom ZSH tilde extension
Context
This involves ZSH wavy expansion (e.g. in bash tilde expansion).
Example: ~http
is extended to /srv
/http, which is (roughly) the home page of the user
.http
set in /etc/ password
What I want to do
I
want to configure ZSH to get any filename squiggly extension I wish.
This is similar to setting alias ~foo/foo/bar
in my .zshrc.
What I don’t want
I could create (as root) the user foo
and set its home page to /foo/bar
, but since any user should be able to do this, such a solution would be Not acceptable.
Also, this has nothing to do with the completion of ~
to $HOME
.
Miscellaneous
This article discusses the nature of the bash wavy line extension: Meaning of tilde in Linux bash (not home directory) .
Thanks for the answer! 😉
Solution
You can use one (or both) of these:
hash -d foo=/foo/bar
(hash
builtin command )foo=/foo/bar/
Now, we can also change the current directory to /foo/bar
using cd ~foo
.
It is called “Static named directories” in zsh.
Note: When > CDABLE_VARS shell option is an event if the directory (/foo/bar
in this example, we can even do cd foo
instead of cd ~foo
in the above example) exists.