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

Re: How to give command line??



Hello, now that I saw this I've got a question kind of related to this: can I apply color dinamically to some part of the cmd line based on the current string typed? For example, given this cmd line string "user@host ~/>% ssh remote@xxxxxxxxxxxxxx", is it possible to apply a, say, red color to the substring "ssh" dinamically (after it's been typed)?


Thanks in advance,
Edgar Merino



Simon Ruderich escribió:
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



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