I keep a file called ansicolor specifically for colorizing terminals (can't remember where I got the idea). It has been particularly useful with setting PS1 variables on the various machines I have to remotely administer. The nice thing about this strategy is that you can define all your color variables once, then simply import the file, whenever needed, with
source /path/to/ansicolor. The file is too long to copy the entire thing, but the first portion is below. The rest of the file is exactly the same, only placing these font colors on various colored backgrounds.
Code:
# Colors on DEFAULT background.
C_BLACK="\[\033[0;30m\]"
C_GRAY_BOLD="\[\033[1;30m\]"
C_RED="\[\033[0;31m\]"
C_RED_BOLD="\[\033[1;31m\]"
C_GREEN="\[\033[0;32m\]"
C_GREEN_BOLD="\[\033[1;32m\]"
C_YELLOW="\[\033[0;33m\]"
C_YELLOW_BOLD="\[\033[1;33m\]"
C_BLUE="\[\033[0;34m\]"
C_BLUE_BOLD="\[\033[1;34m\]"
C_PURPLE="\[\033[0;35m\]"
C_PURPLE_BOLD="\[\033[1;35m\]"
C_CYAN="\[\033[0;36m\]"
C_CYAN_BOLD="\[\033[1;36m\]"
C_WHITE="\[\033[0;37m\]"
C_WHITE_BOLD="\[\033[1;37m\]"
# Color reset.
C_RESET="\[\033[0m\]"
And, to put to use (taken from my root .bashrc):
Code:
source /home/jim/bin/ansicolor
PS1="[$C_RED_BOLD\u$C_RESET@\h \W]\\$ "