[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: colored comman prompt



> is it possible to make the command prompt colored?
> 
> like the escape sequence that you do in DOS?
Yes.  The command prompt is determined from the environment
variable PS1.  Try this:
PS1='\[\e[31m\]\u@\h \[\e[32m\]\t \[\e[33;1m\]\w \[\e[m\e[1m\]\$ \[\e[m\]'
(if you put it in a script, remember to export it)
This should give you a prompt like
user@machine 12:44:23 ~/directory $
where the user@machine part is red, the clock is green, the
current directory is yellow and the rest is white.  This looks best
on an otherwise black background.
The \$ part creates a $ sign for a normal user, and a # if
the user is root.  This is traditional.

Color-changing commands use no character spaces, they are
therefore escaped with a \[ first and a \] after.  Command-line editing
will do strange things if you forget that.
\e is the code for "escape".  The color change commands are the
same ones as in dos, with [33m for brown, [33;1m for yellow and
so on.  Background colors may be set with [4xm where x is in the 0-7 range.
 
> [off topic] 
> how to insert an escape character in vi*?
You don't need to.  For this particular purpose, use "\e" without
quotes.  You will need a proper escape character if you create a colored
textfile though.

Helge Hafting



Reply to: