Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis cellularmitosis/README.md
Last active Oct 19, 2019

Embed
What would you like to do?
Source this in your bashrc for colored username and exit status

Blog 2012/9/9

index | next ->

Colorized Bash prompt

Source this in your ~/.bashrc for colorized username and exit status.

687474703a2f2f692e696d6775722e636f6d2f35323350442e706e67

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.