Text coloring in zsh

(last updated on )
This article wasn't updated in the last ½ year. Please double check if the content is still up-to-date.

If you find any error, please send me a quick heads-up.

You can color your text in zsh by using the %F{...} syntax. To view all available colors use:

for i in {1..256}; do print -P "%F{$i}Color : $i"; done;
Listing all possible colors in zsh

To reset the colors use the special value %F{reset}.

Usage example

I am displaying the current time in on the right hand side of my terminal, in dark gray. The clock will conveniently stop for executed tasks, so that I automatically can see when I started that particular task.

test

You can do that by using the following config in your .zshrc:

# Show timestamp whan a command
# was issued in the right prompt
RPROMPT='%F{240}%D{%H:%M:%S}%F{reset}'

TMOUT=1

TRAPALRM() {
    zle reset-prompt
}

Other Shells

Users of bash can use this guide: When did I run that command?