Skip to content

Instantly share code, notes, and snippets.

@f1337
Last active May 31, 2016 22:34
Show Gist options
  • Save f1337/8810661 to your computer and use it in GitHub Desktop.
Save f1337/8810661 to your computer and use it in GitHub Desktop.
My bash_profile with git branch and status color
source '/usr/local/share/chruby/chruby.sh'
source '/usr/local/share/chruby/auto.sh'
alias ll='ls -la'
# set the bash prompt
function set_bash_prompt () {
SEPARATOR=""
STATUS_COLOR=""
# colors
RED="\[\033[0;91m\]"
GREEN="\[\033[0;92m\]"
YELLOW="\[\033[0;93m\]"
BLUE="\[\033[0;94m\]"
PURPLE="\[\033[0;95m\]"
WHITE="\[\033[1;37m\]"
COLOR_NONE="\[\e[0m\]"
# parse "git branch"
BRANCH=`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ //`
# if BRANCH isn't empty, use a separator
if [[ -n $BRANCH ]]; then
SEPARATOR=":"
fi
# capture "git status"
local git_status="$(git status 2> /dev/null)"
# parse captured status for color
if [[ ${git_status} =~ "working directory clean" ]]; then
STATUS_COLOR="${GREEN}"
elif [[ ${git_status} =~ "Changes to be committed" ]]; then
STATUS_COLOR="${YELLOW}"
else
STATUS_COLOR="${RED}"
fi
# fancy prompt
PS1="${BLUE}\W${COLOR_NONE}${SEPARATOR}${STATUS_COLOR}${BRANCH}${COLOR_NONE} $ "
# iterm title bar
echo -ne "\033]0;${PWD##*/}\007"
}
# Tell bash to execute this function just before displaying its prompt.
PROMPT_COMMAND=set_bash_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment