Created
February 21, 2012 19:57
-
-
Save Jaym3s/1878504 to your computer and use it in GitHub Desktop.
my bash_profile with git status parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ENV=$HOME/.bashrc | |
if [ -f "$ENV" ]; then | |
. "$ENV" | |
fi | |
# adds colors! | |
export CLICOLOR=1 | |
# export LSCOLORS=EHfxCxDxbxegedabagacad # don't need in iterm2 | |
export DISPLAY=:0.0 | |
export LC_CTYPE=en_US.UTF-8 | |
export RI="--format ansi --width 80" | |
export VISUAL=vim | |
if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then | |
. `brew --prefix`/etc/bash_completion.d/git-completion.bash | |
fi | |
# Colours | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[0;33m\]" | |
GREEN="\[\033[0;32m\]" | |
BLUE="\[\033[0;34m\]" | |
LIGHT_RED="\[\033[1;31m\]" | |
LIGHT_GREEN="\[\033[1;32m\]" | |
WHITE="\[\033[1;37m\]" | |
LIGHT_GRAY="\[\033[0;37m\]" | |
COLOR_NONE="\[\e[0m\]" | |
GRAY="\[\033[1;30m\]" | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
export GIT_PS1_SHOWSTASHSTATE=1 | |
export GIT_PS1_SHOWUPSTREAM="auto" | |
function parse_git_branch { | |
if test -n __git_ps1; then | |
branch_parse="\(([^ \*\+\$\%<>\=]+)[ ]?([\*\+\$\%<>\=]*)?\)" | |
branch=`__git_ps1` | |
state="" | |
# unstaged (*) | |
# staged (+) | |
# stashed ($) | |
# untracked (%) | |
# behind (<) | |
# ahead (>) | |
# diverged (<>) | |
if [[ $branch =~ $branch_parse ]]; then | |
branch=${BASH_REMATCH[1]} | |
local_status=${BASH_REMATCH[2]} | |
len=${#local_status} | |
color="${GREEN}" | |
state="" | |
for ((i=0; i < len; i++)) | |
do | |
case ${local_status:$i:1} in | |
'*') | |
color="${RED}" | |
state="${state}${RED}M";; | |
'+') | |
color="${GREEN}" | |
state="${state}${GREEN}M";; | |
'$') | |
color="${BLUE}" | |
state="${state}${BLUE}$";; | |
'%') | |
color="${BLUE}" | |
state="${state}${BLUE}??";; | |
'<>') | |
# diverged | |
color="${RED}" | |
remote_status="${RED}⤧ ";; | |
'>') | |
# ahead | |
color="${RED}" | |
remote_status="${RED}⬆ ";; | |
'<') | |
# behind | |
color="${RED}" | |
remote_status="${RED}⬇ ";; | |
'=') | |
color=${GREEN};; | |
esac | |
done | |
# return the output you want here | |
echo "($color$branch${COLOR_NONE})$state$remote_status" # ($local_status)" | |
else | |
echo "$branch" | |
fi | |
fi | |
} | |
#sets what the prompt should be | |
function prompt_func() { | |
previous_return_value=$?; | |
prompt="$(parse_git_branch)${COLOR_NONE}" | |
if test $previous_return_value -eq 0 | |
then | |
PS1="${LIGHT_GRAY}侍 ${COLOR_NONE}${prompt}\W/ " | |
else | |
PS1="${RED}侍 ${COLOR_NONE}${prompt}\W/ " | |
fi | |
} | |
PROMPT_COMMAND=prompt_func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment