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

PROMPT="$(parse_git_branch)"

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

link|improve this question

74% accept rate
feedback

2 Answers

up vote 4 down vote accepted

you have to

setopt PROMPT_SUBST

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.

link|improve this answer
feedback

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

setopt PROMPT_SUBST
PROMPT='$(parse_git_branch)'

or better

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

Your Answer

 
or
required, but never shown

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