2

I have my prompt set to the following:

PROMPT=%F{reset}[%F{blue}%2/%F{reset}]

which displays two parent directories as

[foo/bar]

However, when I'm in $HOME or one directory deep in $HOME, I'd like the prompt to be displayed as

[~]
[~/foo]

respectively, instead of

[/Users/me]
[me/foo]

I've tried approaches like Steve Losh's collapse_pwd (and the simpler version: ${PWD/#$HOME/~} also mentioned in the article) and other similar ones, but I lose the flexibility of being able to show only the last two directories.

How can I modify the above to handle $HOME? My zsh version is zsh 5.0.0 (x86_64-apple-darwin12.0.0) on OS X 10.8.2

1 Answer 1

4

zsh has built-in support for that. Use %2~ instead of %2/. See also %40<...<%~

See also the autonamedirs option:

$ l=/usr/local
$ PS1='%~$ '
~$ setopt autonamedirs
~$ cd /usr/local
~l$ 

(without autonamedirs, you can still do cd ~l to cd to /usr/local and your prompt to show ~l).

0

You must log in to answer this question.