You need to enable the AUTO_NAME_DIRS
option in your Zsh configuration
setopt autonamedirs
it has to happen before you set PROJ
.
Alternatively, if you do not need PROJ
for anything other than switching (and displaying) paths in Zsh, you can set
hash -d PROJ=$HOME/project
Explanation:
The feature you are using is called "Static named directories". Usually named directories need do be called with a ~
followed by the name of a shell parameter whose value begins with a /
, PROJ
in your case.
If CDABLE_VARS
is enabled (which Oh-My-Zsh does by default) the ~
is not really required. That is why you can use PROJ/project_name
instead of ~PROJ/project_name
. (but it would fail, if there were a directory with the actual name PROJ
).
As Oh-My-Zsh also enables AUTO_CD
you do not even need to use cd
. If a command cannot be executed and matches the name of a directory, Zsh will cd
to that directory.
With all named directories lookups may happen in two directions
- does a given name point to a directory (e.g. does a parameter contain a path starting with
/
)?
- does the current directory have a name?
While the first kind of lookup happens automatically when an argument starts with ~
(or in some cases and enabled CDABLE_VARS
even without), the second kind (which is used for the prompt) requires the directory to be listed in the directory hash table (hash -d
for a listing of that table). On a freshly started Zsh this hash table is usally empty. It will then be filled with data acquired when doing ~
expansions.
In your original shell PROJ
has been successfully expanded to $HOME/projects
and so the directory hash table now contains PROJ=$HOME/projects
(where $HOME
is replaced with your actual home directory path). Zsh can now look it up for its prompt. When you start tmux, a new shell is started and the directory hash table is again empty, thus the name is not replaced in the prompt.
With AUTO_NAME_DIRS
an entry in the directory hash table is created immediately when a parameter is set to a value that starts with /
(or it is removed if the new value does not start with /
). You can also add manually to the directory hash table with hash -d NAME=PATH
.
It's working now. Thanks for the complete response. – Dimas Kotvan – 2015-04-16T16:53:59.363