Blog 2012/9/9
Source this in your ~/.bashrc for colorized username and exit status.
Don't forget to copy this into root's bashrc as well!
| # source this in your bashrc for colorized username and exit status. | |
| # see https://gist.github.com/gists/3686357 | |
| # see http://i.imgur.com/523PD.png | |
| # don't forget to copy this into root's bashrc as well | |
| # --- colors for prompt | |
| COLOR_RED="\[\e[31;40m\]" | |
| COLOR_GREEN="\[\e[32;40m\]" | |
| COLOR_YELLOW="\[\e[33;40m\]" | |
| COLOR_BLUE="\[\e[34;40m\]" | |
| COLOR_MAGENTA="\[\e[35;40m\]" | |
| COLOR_CYAN="\[\e[36;40m\]" | |
| COLOR_RED_BOLD="\[\e[31;1m\]" | |
| COLOR_GREEN_BOLD="\[\e[32;1m\]" | |
| COLOR_YELLOW_BOLD="\[\e[33;1m\]" | |
| COLOR_BLUE_BOLD="\[\e[34;1m\]" | |
| COLOR_MAGENTA_BOLD="\[\e[35;1m\]" | |
| COLOR_CYAN_BOLD="\[\e[36;1m\]" | |
| COLOR_NONE="\[\e[0m\]" | |
| # --- prompt | |
| promptFunc() | |
| { | |
| PREV_RET_VAL=$?; | |
| PS1="" | |
| # $USER seems unreliable. use whoami instead. | |
| #if test "$USER" != "root" | |
| if test "`whoami`" != "root" | |
| then | |
| PS1="${PS1}${COLOR_CYAN_BOLD}\u${COLOR_NONE}" | |
| else | |
| PS1="${PS1}${COLOR_RED_BOLD}\u${COLOR_NONE}" | |
| fi | |
| PS1="${PS1}@\h" | |
| if test $PREV_RET_VAL -eq 0 | |
| then | |
| PS1="${PS1}${COLOR_GREEN_BOLD}\\$ ${COLOR_NONE}" | |
| else | |
| PS1="${PS1}${COLOR_RED_BOLD}\\$ [${PREV_RET_VAL}] ${COLOR_NONE}" | |
| fi | |
| } | |
| PROMPT_COMMAND=promptFunc |