How can I change the color of my prompt in zsh (different from normal text)?
Put this in ~/.zshrc
:
autoload -U colors && colors
PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
Supported Colors:red
, blue
, green
, cyan
, yellow
, magenta
, black
, & white
(from this answer) although different computers may have different valid options.
Surround color codes (and any other non-printable chars) with %{....%}
. This is for the text wrapping to work correctly.
Additionally, here is how you can get this to work with the directory-trimming from here.
PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%(5~|%-1~/.../%3~|%4~) %{$reset_color%}%% "
Zsh comes with colored prompts builtin. Try
autoload -U promptinit && promptinit
and then prompt -l
lists available prompts, -p fire
previews the "fire" prompt, -s fire
sets it.
When you are ready to add a prompt add something like this below the autoload line above:
prompt fade red
Here's an example of how to set a red prompt:
PS1=$'\e[0;31m$ \e[0m'
The magic is the \e[0;31m
(turn on red foreground) and \e[0m
(turn off character attributes). These are called escape sequences. Different escape sequences give you different results, from absolute cursor positioning, to color, to being able to change the title bar of your window, and so on.
For more on escape sequences, see the wikipedia entry on ANSI escape codes