Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm adjusting my zsh prompt, based upon the dallas theme and the dstufft theme from oh-my-zsh. I love how dallas has various sections of the prompt contained in variables, which makes it much easier to understand what's going on.

The problem is, these strings are evaluated once for expansion. So when I attempt to use something dynamic, such as the ${PWD/#$HOME/~} of dstufft, then it no longer updates dynamically.

How can I get the best of both worlds? I'd like the prompt broken up into subsections that are evaluated each time the prompt gets written.

share|improve this question
up vote 3 down vote accepted

Make sure that the prompt_subst option is turned on. If necessary, add the following line to your ~/.zshrc:

setopt prompt_subst

This tells zsh to reevaluate the prompt string each time it's displaying a prompt. Then, make sure you are assigning PS1 (or some other variable that is used by the prompt theme) as desired:


The single quotes protect the special characters such as $ from being evaluated when you set the variable.

share|improve this answer
Oh duh! I can't believe I was using double quotes instead of single quotes. Too much Windoze... – Spencer Rathbun Jun 13 '12 at 12:29


I just need to escape my $ signs. For example:

share|improve this answer

In zsh you should use % escapes for this. For example, instead of ${PWD/#$HOME/~} (as your example), just use %~.

Read zshall(1) and look for SIMPLE PROMPT ESCAPES (it's too long to quote here).

share|improve this answer
I'm following Steve's approach here. You can see the issue that %~ brings up. I'm also running some functions in the prompt. – Spencer Rathbun Jun 12 '12 at 17:57
@SpencerRathbun unsetopt cdable_vars would solve the issue of environment variables creeping into %~. – Gilles Jun 12 '12 at 22:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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