Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

color prompts and $' evaluation - zsh-3.1.4 required?



The ZSH FAQ from 23rd March 2000 mentions how to set your prompt
to get colors.  It says that evaluation with "$'" is required.
I found that this works with zsh-3.1.4 but not with zsh-3.1.2.
I think a note about the required version is needed -
it makes people upgrade, you know.  ;-)

Sven

===
3.25: How do I get coloured prompts on my colour xterm?

(Or `color xterm', if you're reading this in black and white.)  You need to
find the sequences which generate the various colours from the manual;
these are ANSI standard on the terminal emulators I know about which
support colour.  With a recent (post 3.1.6) distribution of zsh, there is a
theme system to handle this for you; even if you don't see that, the
installed function ``colors'' (meaning `colours', if you're not reading
this in black and white) gives the escape sequences.  You will end up with
code looking like this (borrowed from Oliver Kiddle):

  PS1=$'%{\e[1;31m%}<the rest of your prompt here>%{\e[0m%}'

The `$'' form of quoting turns the ``\e'' into a real escape
character.  The ``%{...%}'' is used in prompts for strings which will
not appear as characters, so that the prompt code doesn't miscalculate
the length of the prompt which would have a bad effect on editing.
The resulting ``<ESC>[1;31m'' makes the prompt red, and the ``<ESC>[0m''
puts printing back to normal so that the rest of the line is unchanged.



Messages sorted by: Reverse Date, Date, Thread, Author