3

Context

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.

What I want to do

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.

What I do not want

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.

Misc

This post discuss the nature of bash tilde expansion: Meaning of tilde in Linux bash (not home directory).

Thanks for any answer! ;-)

Community
  • 1
  • 1
Arcturus B
  • 5,181
  • 4
  • 31
  • 51

1 Answers1

4

You could use either (or both) way:

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.

hchbaw
  • 4,894
  • 18
  • 16