Viet
Viet

Reputation: 6953

MacOS zsh prompt does not show Purple?

I'm trying to make my git branch purple. Here's what I have:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    # git symbolic-ref --short HEAD 2> /dev/null
}

setopt PROMPT_SUBST
PS1='%{%F{green}%}%n@%m:%{%F{yellow}%}%1~%{%F{red}%}$(parse_git_branch)%{%F{none}%}$ '

So my username@machine: is green and foldername is yellow as expected. However, if I change the colour red to purple or anything else but white or cyan, my prompt doesn't show the correct colour.

FYI: Here's what I have in bash:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[0;32m\]\u@\h\[\033[00m\]:\[\033[0;33m\]\W\[\033[0;35m\]\$(parse_git_branch)\[\033[00m\]\$ "

I've tried:

What am I missing?

Upvotes: 0

Views: 1584

Answers (1)

chepner
chepner

Reputation: 532303

With %F{...}, you can use one of the following:

  1. An integer corresponding to an entry in your terminal's palette (the range depends on the size of that palette). That's what you saw with your for loop (though you can use i=0 as well; see the next point). E.g. %F{red}

  2. One of the predefined names black, red, green, yellow, blue, magenta, cyan, or white (corresponding to palette entries 0 through 7, respectively). E.g. %F{1} (Note that some terminals may support additional names.)

  3. An RGB value, starting with a # and followed by 3 or 6 hexadecimal digits. E.g. %F{#f00} or %F{#ff0000}`

    Assuming your terminal allows it, this provides you with more control over the color displayed, as both %F{red} and %F{1} simply tell the terminal to display color #1 (which the terminal emulator may allow to be set to any color the user likes). %F{#ff0000}, on the other hand, will always display the brightest shade of red available.

Upvotes: 2

Related Questions