On Mon, Oct 05, 2009 at 01:49:55PM -0700, Guido van Steen wrote:
Hi,
[snip]
Is there a way - possibly using ZLE - to give different parts
of the command line different colors, e.g. can I make the first
word green, the second word red and so on?
Thanks!
Guido
Hi Guido,
Of course this is possible. Here is an example (part of my
prompt).
# Color support, necessary for ${fg[...]}.
autoload -U colors && colors
PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
%{${fg[blue]}%}%B%~%b%{${fg[default]}%}%# "
It colors %m (hostname) in green and bold (%B and %b), then
resets the color to default and draws : in the default color,
then draws %~ (current directory) in blue and bold and resets the
colors again, then draws the % with %# (or $ for root) in the
default color.
The %{..%} around the colors are necessary to tell Zsh that the
colors don't take any space so it can draw the prompt correctly.
For more information see man zshmisc and search for SIMPLE PROMPT
ESCAPES (it's at the end of the file) and man zshcontrib and
search for colors (the second occurrence).
Hope this helps,
Simon