Skip to content

Instantly share code, notes, and snippets.

@nukemberg
Last active August 29, 2015 14:20
Show Gist options
  • Save nukemberg/02c289fb689eb1c58690 to your computer and use it in GitHub Desktop.
Save nukemberg/02c289fb689eb1c58690 to your computer and use it in GitHub Desktop.
workspace prompt for bash
BLUE="34;1m"
ORANGE="33m"
GREEN="32m"
RED="31m"
ROOT_COLOR="31;4m"
ENV_COLOR="$GREEN" # set from puppet or chef, should be RED for prod
function _colorify() {
echo -en "\[\e[$1\]$2\[\e[0m\]"
}
function _user_color() {
if [[ "$UID" -eq 0 ]]; then
echo -en "$(_colorify $ROOT_COLOR "$1")"
else
echo -n "$1"
fi
}
function _prompt_command() {
ret=$?
PS1="${_PS1}"
if [[ $ret -ne 0 ]]; then
PS1="$(_colorify "$ORANGE" "[$ret]"):$PS1"
fi
}
_PS1="$(_user_color "\u")@$(_colorify $ENV_COLOR "\h"):$(_colorify "$BLUE" "\w")$ "
PROMPT_COMMAND="_prompt_command"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment