Tip #376 Change prompt color dynamically
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> "
.colors.sh:
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
- TAGS:
- bash
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs