Subject: Re: Using color in PS1 of the Korn Shell with ANSI escape codes
To: Gilbert Fernandes <gilbert.fernandes@spamcop.net>
From: Pavel Cahyna <pavel.cahyna@st.mff.cuni.cz>
List: netbsd-users
Date: 12/26/2005 16:56:49
On Mon, Dec 26, 2005 at 03:17:32AM +0100, Gilbert Fernandes wrote:
> 
> (using Korn Shell)
> 
> I have been trying to add some color to my PS1 but the ANSI color escape
> codes don't seem to be parsed or seen at all.
> 
> My current PS1 is :
> 
> PS1='
> {$PWD}
> [$LOGNAME][!] '
> 
> So it jumps a line, displays the current path, then on the line that follows
> show the current username and current command number.
> 
> For example :
> 
> {/usr/home/gilb}
> [gilb][13]
> 
> (12 commands typed, waiting for 13)
> 
> I do edit the .profile using vi. If I want to write the name in bright red
> example I need to insert the following escape sequence :
> 
> PS1='
> {$PWD}
> \[1;31m$LOGNAME\[m][!] '
> 
> To insert the control sequence I use control-V, then the escape key. I then
> type the color codes (0;34) and I finish with the "m" which marks the end
> of the ANSI color escape sequence.

Use the tput command instead. E.g. PS1="$(tput AF 2)${PS1}" works for me.

(I don't use such tricks anymore because they confuse the line editing -
the length of the prompt can't be determined correctly anymore.)

Pavel Cahyna