Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define custom colors for use in ZSH prompt?

I'm having some difficulty configuring my zsh prompt. Specifically I would like the font to have the color defined by the hex code: #87afdf

Currently, I've set up the prompt as follows:

PROMPT='%B[%d] 
➞  %b'

I've attempted to add colors in the following way:

autoload -U colors && colors

PROMPT='%{$fg[#87afdf]%}%B[%d]
➞  %b%{$reset_color%}'

But this only gives me the following gibberish:

$fg[#87afdf][/Users/gregory]
➞  $reset_color

Any ideas on how to proceed would be very much appreciated.

like image 399
ggelfond Avatar asked Dec 13 '12 22:12

ggelfond


People also ask

How do I customize my zsh prompt?

To customize the ZSH prompt, we need to modify the prompt= variable inside the . zshrc file. We can populate the prompt variable with various placeholders, which will alter how the ZSH prompt appears.

How do I change zsh prompt on Mac?

To make any change to the default zsh prompt, you'll have to add relevant values for the prompt to appear differently than the default. It'll be blank if you're accessing it for the first time. You can add a new line with the text PROMPT='...' and include relevant values in the ellipses.


1 Answers

You have to use a 256-color palette. You can see the numerical values for each of the 256 colors in ZSH using the following command:

for code in {000..255}; do print -P -- "$code: %F{$code}Color%f"; done

The same for bash:

for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Color"; done
like image 94
OneOfAKind_12 Avatar answered Sep 19 '22 08:09

OneOfAKind_12