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