Super User is a question and answer site for computer enthusiasts and power users. 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

This works in Bash (parse_git_branch is a defined function)

export PS1="\$(parse_git_branch)"

but I cannot figure out the equivalent in zsh.

Note: If I do


it seems to work, but in fact it's running the command when I set the prompt, which is not the point.

share|improve this question
up vote 13 down vote accepted

you have to


in your .zshrc, man zshall explains it in the PROMPT EXPANSION section:

If the PROMPT_SUBST option is set, the prompt string is first subjected to parameter expansion, command substitution and arithmetic expansion.

share|improve this answer

Actually your problem was not just setting PROMPT_SUBST: you use double quotes in your script forcing the evaluation of the function when you set the PROMPT variables. You only want evaluation when the prompt is computed that is you must use single quotes.

share|improve this answer

As akira says, you have to use prompt subst. This is my early code (still working on it):


or better

PROMPT='[$PR_MAGENTA%n$PR_NO_COLOR@$PR_GREEN%U%m%u$PR_NO_COLOR:$PR_RED%2c$PR_NO_COLOR]$(parse_git_branch) %(!.#.$)'
share|improve this answer

You must log in to answer this question.

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