Reputation: 6953
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:
for i in {1..256}; do print -P "%F{$i}Color : $i"; done;
and my terminal shows all ranges of colours so I replaced red
with some ANSI code but the branch turns cyan
.\e[0;31m$ \e[0m
with ANSI escape char but it still doesn't work.$F{}
, $fg{}
, etc.~/.zshrc
file, restart computer.What am I missing?
Upvotes: 0
Views: 1584
Reputation: 532303
With %F{...}
, you can use one of the following:
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}
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.)
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