1

I'm using precmd to generate a coloured git status in my prompt.

I generate a sting like %F{green}master%f%F{red}%f, and assign it to $psvar[1].

My prompt includes %1v to display the text.

However, I'm not seeing green and red text, but rather the literal value that was assigned.

Is there any way to get zsh to parse the contents of $psvar?

1

Prompt expansion isn't recursive. You have %1v in your prompt, so the content of $psvar[1] is inserted in your prompt.

Instead of putting prompt expansion directives in $psvar, put prompt contents. Insert the terminal escape sequences for color changes. You can use colors for that.

autoload -U colors
colors
… {
  psvar[1]="$fg[green]$branch$fg[default]"
}
0

This zsh-users mailing list post says:

The results of percent-expandos are not re-expanded, so whatever gets inserted by %v appears literally in the final prompt.

So it seems the only way is to use set -o prompt_subst.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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