tags:

views:

2458

answers:

2

To recognize better the start and the end of output on a commandline, I want to change the color of my prompt, so that it is visibly different from the programs output. As I use zsh, can anyone give me a hint?

+2  A: 

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

Bryan Oakley
Thank's alot, that helps.
Mnementh
I am using PROMPT='[%!]' in my .zshrc. How can you color it? I run unsuccessfully PROMPT='\e[0;31m[%!] \e[0m' in my .zshrc.
Masi
If you do not wrap your *zsh* prompt escape sequences in `%{` `%}`, it can create confusing redisplay issues (e.g. when typing long commands, editing a command line, moving though history, etc.).
Chris Johnsen
+10  A: 

Put this in ~/.zshrc:

autoload -U colors && colors

PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "

fireDude67