Skip to content

Instantly share code, notes, and snippets.

@jFransham
Created October 23, 2015 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jFransham/f2ce3911a1abb790b185 to your computer and use it in GitHub Desktop.
Save jFransham/f2ce3911a1abb790b185 to your computer and use it in GitHub Desktop.
__git_ps1() {
if [ "$(git status -s 2>&1 1>/dev/null)" ]; then
return
fi
local nn=$(git status -s 2>/dev/null | grep "??" | sed -n '$=')
local nc=$(git status -s 2>/dev/null | grep M | sed -n '$=')
local branch=$(git branch 2>/dev/null | grep "*" | sed 's/^* //')
nn=$nn
nc=$nc
local msg=""
local color=""
local uncolor=`echo -e "\033[0m"`
if [ $(git diff --name-only HEAD origin/$branch 2>/dev/null | sed -n '$=') ]; then
color=`echo -e "\033[1;31m>>"`
elif [ $(git status | grep -i "your branch is behind 'origin/") ]; then
color=`echo -e "\033[0;31m<<"`
else
color=`echo -e "\033[1;32m"`
fi
if [ $nc ]; then
msg=$msg"-"$nc"c"
fi
if [ $nn ]; then
if [ $msg ]; then
msg=$msg","$nn"n"
else
msg=$msg"-"$nn"n"
fi
fi
echo -e "($color$branch$uncolor$msg)"
}
export PS1='[\u \w$(__git_ps1)]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment