I have a wierd problem with my zsh on my OSX 10.8 (with oh-my-zsh, which I think has AUTO_NAME_DIRS set for me).

Normally if I set up an environment variable to some path by export SOME_VAR=/some/path, and switch to that path, I will have ~SOME_VAR in my command line prompt. This works fine on my Ubuntu 13.04 with zsh 5.0.0.

However, on my OSX 10.8, it works only for certain variable names. For example, some logs from my terminal:

Last login: Fri Jul 26 10:22:15 on ttys000
sji@MacBook-Air:~% cd dev/test
sji@MacBook-Air:~/dev/test% export QEPY_PATH=`pwd`
sji@MacBook-Air:~/dev/test% export AEPY_PATH=`pwd`
sji@MacBook-Air:~/dev/test% export EEPY_PATH=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PATH=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PTH=`pwd` 
sji@MacBook-Air:~/dev/test% export AAAAEPY_PBTH=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PDTH=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PDDH=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PDIO=`pwd`
sji@MacBook-Air:~/dev/test% export AAAAEPY_PAT=`pwd` 
sji@MacBook-Air:~/dev/test% export AEPY_PAT=`pwd` 

All but the last one didn't work for me. At first, I thought it's because the zsh on OSX is too old. But the problem still persists after I upgraded it to 5.0.2 through MacPorts.

I struggled for some time but still couldn't find the pattern that which variable names are acceptable and which are not.

Has anyone some ideas? Thanks.

2 Answers 2


The %~ expansion is used to try to find the most concise way of representing your location, since prompt space is precious and there's no point saying more than is needed.

Thus in zshexpn(1) the section Static named directories explains how the shortest way of referring to the directory is used, and the rules for breaking ties (favouring named dirs).

Since /dev/test is 9 characters, and ~ is 1 character, your variable name can be at most 8 characters for the rules to favour using the variable.


I am more surprised that ~AEPY_PAT is immediately shown in the prompt. To my understanding you had to use argument expansion once on the named dirs (with : ~name which does nothing apart from argument expansion, but it of course happens also with e.g. cd ~name) prior their first usage.

This is on Linux with zsh 5.0.2:

~/temp> export foo=`pwd`
~/temp> : ~foo

Only after : ~foo the named dir shows up in the prompt.

I suppose that you used ~AEPY_PAT earlier that session (e.g. in you rc files) and that's why this is working directly, but not for other names.

  • Sorry, I must admit I didn't paid enough attention to your question title, and missed that you have AUTO_NAME_DIRS set. I agree, that should do the argument expansion automatically.
    – mpy
    Jul 26, 2013 at 15:14
  • Yes, I think oh-my-zsh has AUTO_NAME_DIRS set by default.
    – tomzhi
    Jul 26, 2013 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .