Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can ksh prompt (PS1) be colored?

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
please give me some examples if it is possible.

I am using putty
 
Not sure about putty, but:

export PS1=`echo "\033[36m"``uname -n`'$PWD''...'`echo "\033[31m\033[1m"`'$LOGNAME'`echo "\n\033[37m\033[0m"`'>'

gives you a $PS1 with servername/working directory/...username> (before the '...' in blue, after it in red).

There are probably easier ways to set this up, however!
 
Yes, it seems not possible to turn the color around in the middle of a screen line...

Code:
ps1='#'                      # better use a case or if/else here: root -> # otherwise -> $
REDONYELLOW="^[[0;31;43m"    # insert ESC char with ctrl-V ESC
WHITEONBLACK="^[[0;37;40m"   # same here
PS1=${REDONYELLOW}$(hostname):'[$PWD]${WHITEONBLACK}
${ps1} '


the numbers for atrributes/foreground color/background color can be found on the web (Google's lucky shot):
I also tried "tput setf 1" and "tput setb 3" to make this more portable but that does not seem to work for xterm/putty - I guess the xterm terminfo is incomplete?



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top