16 Colors in ZShell
Solution 1
What terminal emulator are you using? You can check the number of supported colors by running echotc Co
. For example, my urxvt
supports 88 colors, but xterm
supports only 8, and bright variations are not included.
If I run it in urxvt
I get:
# Dark magenta/violet:
PS1="[%F{34}%n%F{reset}@%F{magenta}%m%F{reset} %.] "
# Bright Thistle purple:
PS1="[%F{54}%n%F{reset}@%F{magenta}%m%F{reset} %.] "
Sources: man zshall
Solution 2
All “colors” you are talking about are just escape sequences in a form \e[{color_code}m
. Zsh function colors
does nothing more then adding a few zsh associative array variables mapping human-readable color names to terminal escape sequences. Thus you can either directly use
PS1=%{$'\e[54m'%}...
or try out @Mischa Arefiev’s answer, it is more readable. Note that escape sequences work in any shell, while constructions like %F{54}...
work only in zsh.
Related videos on Youtube
Tammer Ibrahim
Updated on September 18, 2022Comments
-
Tammer Ibrahim over 1 year
I only seem to be able to call 8 colors in my zshell prompt.
Example:
PROMPT="[%n@%{$fg[magenta]%}%m%{$reset_color%} %.] %# "
Works fine. However,
PROMPT="[%n@%{$fg[brmagenta]%}%m%{$reset_color%} %.] %# "
Doesn't work. Basically, none of the "bright" color variations appear.
After doing some research, I found that zsh's colors are called by the "colors" setopt.
doing
echo ${(o)color}
yields this output:
00 01 02 03 04 05 07 08 22 23 24 25 27 28 30 30 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 39 39 40 40 41 42 43 44 45 46 47 49 bg-black bg-blue bg-cyan bg-default bg-green bg-magenta bg-red bg-white bg-yellow black blink blue bold conceal cyan default faint green magenta no-blink no-conceal no-reverse no-standout no-underline none normal red reverse standout underline white yellow
As you can see, only the standard 8 colors are available. I've tried using the "bg-" variants, which also leave the output as the default text color.
Any help you can provide will be greatly appreciated. I could, of course, just use one of the normal colors, but then I'd learn nothing!