//View Tip #376
Similar Tips
» Get latest stable version of the Linux kernel
» swap files
» Bash terminal size
» SSH Auto Complete
» SVN resolve all conflicts


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
I'm frequently logged into multiple different boxes concurrently. To help me keep track of which box I'm working on at the moment, I have this in my .bashrc file, which I keep rsynced across the various boxes.

# defines the color variables used below, including ${Normal} # google "tput setaf" and "tput setab" for more information . ~/.colors.sh if [ `id -u` -eq 0 ]; then Color=${RedBG}${White} # red background for root else case `hostname` in machine1 ) Color=${Blue} ;; machine2 ) Color=${Green} ;; machine3 ) Color=${Cyan} ;; machine4 ) Color=${Purple} ;; * ) Color=${Yellow} ;; esac fi PS1="${Color}$PS1${Normal}\n> "


Black="$(tput setaf 0)"
BlackBG="$(tput setab 0)"
DarkGrey="$(tput bold ; tput setaf 0)"
LightGrey="$(tput setaf 7)"
LightGreyBG="$(tput setab 7)"
White="$(tput bold ; tput setaf 7)"
Red="$(tput setaf 1)"
RedBG="$(tput setab 1)"
LightRed="$(tput bold ; tput setaf 1)"
Green="$(tput setaf 2)"
GreenBG="$(tput setab 2)"
LightGreen="$(tput bold ; tput setaf 2)"
Brown="$(tput setaf 3)"
BrownBG="$(tput setab 3)"
Yellow="$(tput bold ; tput setaf 3)"
Blue="$(tput setaf 4)"
BlueBG="$(tput setab 4)"
LightBlue="$(tput bold ; tput setaf 4)"
Purple="$(tput setaf 5)"
PurpleBG="$(tput setab 5)"
Pink="$(tput bold ; tput setaf 5)"
Cyan="$(tput setaf 6)"
CyanBG="$(tput setab 6)"
LightCyan="$(tput bold ; tput setaf 6)"
Normal="$(tput sgr0)" # No Color

View Comments »


Add your comment

Comments are currently disabled
Silly me, and I've been typing in those ANSI escape sequences all along.  Thanks for the tput examples.

I also do a kind of hash on the hostname (instead of a case statement) to cover a larger number of host names.  The following example gets 9 colors out of any number of host names:

case "$(( $( dc -e "$( hostname | cksum ) - p ) % 9 ))"

For user and group, I use a similar technique except that system level id's are separately detected to be marked with very bold colors.

Thanks Again.
Posted 2008-10-13 09:39:03

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit