6

I just installed zsh and oh-my-zsh and I would like to use the named directories feature, i.e.

% hash -d foo=/etc

% echo ~foo
/etc

However, when I restart my console, these settings are gone. How do I make them permanent?

How do I edit them if, say, I make a typeo when setting the "alias" name.

Where is the best place to look for documentation of zsh?

Is this it? http://zsh.sourceforge.net/Doc/Release/zsh_toc.html

2
  • I don't use zsh, but I imagine you could put that in the .zshrc. If you make a typo while using the shell, you could delete the incorrect name, then run the corrected command.
    – wjandrea
    May 30, 2018 at 15:44
  • Note that for ordinary shell variables (the zsh doc calls them "parameters") that begin with a / become named directories, so in the example, foo=/etc suffices.
    – JohnLittle
    Feb 23 at 2:09

2 Answers 2

7

Set static named directories

Open up ~/.zshrc in your favorite editor and add the hash commands one after one like you did in your example, e. g.

hash -d foo=/etc
hash -d zshdoc=/usr/share/doc/zsh-common

and so on. The file .zshrc in your home directory will be loaded every time you start zsh.

Aliases

You can also put your alias definitions there, just the same way. However, it is more useful to put aliases in a separate file, e. g. ~/.zshaliases and then source this file from .zshrc. So, add this to .zshrc:

. ~/.zshaliases

and then add your alias definitions to ~/.zshaliases like this:

alias ll="ls -l"
alias la="ls -la"

These are just examples of course. The reason to put those aliases in a separate file is, that you can edit it with your favorite editor and then simply reload all aliases by issuing the command . ~/.zshaliases.

Documentation

Personally I like most the zshall manual page which you can open by running the command man zshall. It is very complete.

Other good sources for zsh documentation are:

0

There are two ways: by editing ~/.zshrc or by adding an alias in a separate file. The latter one is more recommended by ZSH creators. See the full "receipt" here.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.