Get Function Into PS1 (Zsh)?

Solution 1:

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.

Solution 2:

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.