This concerns ZSH tilde expansion (as in bash tilde expansion).
Example: ~http
is expanded to /srv/http
which is (roughly) the home for user http
set in /etc/passwd
.
I would like to configure ZSH in order to get any filename tilde expansion I wish.
This would be something like setting alias ~foo /foo/bar
in my .zshrc
.
I could create (as root) the user foo
and set it’s home to /foo/bar
but since any user should be able to do this, such a solution is not acceptable.
Also, this has nothing to do with the completion of ~
to $HOME
.
This post discuss the nature of bash tilde expansion: Meaning of tilde in Linux bash (not home directory).
Thanks for any answer! ;-)
You could use either (or both) way:
hash -d foo=/foo/bar
(hash
builtin command)foo=/foo/bar/
Now, we could use cd ~foo
to change the current directory to /foo/bar
, too.
It is known as “Static named directories” in zsh.
Note: when CDABLE_VARS
shell option is active, we could do even cd foo
rather than cd ~foo
in the above example if the directory (/foo/bar
in this example) exists.