[ILUG] Colour Prompts

[ILUG] Colour Prompts

Colm Buckley colm at tuatha.org
Fri Dec 17 13:58:43 GMT 1999


> In bash it's possible to set the colour of the prompt [...]
> The question is, is there an easy way to do this under csh (that's the only
> shell we have use of here in work on the Sun boxen)

Look.  Grr.  This is the Wrong Thing.  The Unix terminal interface has
been carefully crafted over the past 30 years to be independent of any
particular terminal type; with thousands of hours of effort going into
libraries like terminfo and curses.  Putting terminal-specific codes
into your prompt (or elsewhere) is gratuitous breakage...

You should use the terminfo database to get the correct color-changing
codes for your terminal.  Assuming TERM is set correctly (eg: to
"xterm-color"), you can use the "tput" command to get the correct
color-changing codes.

Red is color 1 in the ANSI color scheme, so for most terminals you can
do something like:

(sh-like version)

[ `tput colors` -gt 0 ] && PS1="`tput setaf 1`text here`tput setaf 0`"

(csh-like version)

if ( `tput colors` > 0 ) set prompt="`tput setaf 1`text here`tput setaf 0`"

Enjoy,

        Colm

-- 
Colm Buckley B.A. B.F. # colm at tuatha.org colm.buckley at cs.tcd.ie
Department of Computer Science      # +353 87 2469146 # whois cb3765
Trinity College, Dublin 2, Ireland. # http://www.tuatha.org/~colm/
Experience allows us to recognise our mistakes when we make them again.




More information about the ILUG mailing list