Get Function Into PS1 (Zsh)?

You have to include

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.


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.


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) %(!.#.$)'

Tags:

Prompt

Zsh