I have assigned a directory to a variable in my .zshrc file like so:
export DOTFILES=$HOME/.dotfiles
Now my zsh prompt reads ~DOTFILES
when I am in the .dotfiles
directory. I did some research (in this thread: Variable names in prompt instead of path) and found that zsh has an AUTO_NAME_DIRS
option which does this very thing.
I tried unsetopt AUTO_NAME_DIRS
but my zsh prompt still shows the variable name instead of the path. I ran the unsetopt
command and found that autonamedirs
is indeed in the list of unset options. I also ran setopt
to make sure it wasn't in the list of set options, and it is not.
Any ideas on how to fix this?
Think of it as a hook to create named directories that is triggered at variable setting.
So if auto_name_dirs
parameter is set and you set some value % TMP=/tmp
, it will also create a named dir for /tmp
using TMP
. If you later unset the parameter, the directory name remains. If you create a number of variables % USER=/usr
with auto_name_dirs
unset, and after set the option, no directory naming will take place.
~ % zsh -f
dhcp-193-107% setopt autonamedirs
dhcp-193-107% TMP=/tmp
dhcp-193-107% export PS1="dir-prompt %~ : "
dir-prompt ~ : cd /tmp
dir-prompt ~TMP : unset autonamedirs
dir-prompt ~TMP : cd /
dir-prompt / : cd /tmp
dir-prompt ~TMP : # see the dir name still exists
dir-prompt ~TMP : USER=/usr
dir-prompt ~TMP : cd /usr
dir-prompt /usr : # no dir name for /usr
dir-prompt /usr : setopt autonamedirs
dir-prompt /usr : cd /
dir-prompt / : cd /usr
dir-prompt /usr : # still no dir name for /usr