Hack 39. Display multiple colors in the prompt
by Ramesh
You can also display multiple colors in the same prompt. Add the following function to your ~/.bash_profile
- function prompt {
- local BLUE="\[\033[0;34m\]"
- local DARK_BLUE="\[\033[1;34m\]”
- local RED=”\[\033[0;31m\]”
- local DARK_RED=”\[\033[1;31m\]”
- local NO_COLOR=”\[\033[0m\]”
- case $TERM in
- xterm*|rxvt*)
- TITLEBAR=’\[\033]0;\u@\h:\w\007\]’
- ;;
- *)
- TITLEBAR=”"
- ;;
- esac
- PS1=”\u@\h [\t]> ”
- PS1=”${TITLEBAR}\
- $BLUE\u@\h $RED[\t]>$NO_COLOR ”
- PS2=’continue-> ‘
- PS4=’$0.$LINENO+ ‘
- }
You can re-login for the changes to take effect or source the .bash_profile as shown below.
- $. ./.bash_profile
- $ prompt
- ramesh@dev-db [13:02:13]>
当前内容版权归 Ramesh Natarajan 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Ramesh Natarajan .