Created
October 23, 2015 12:06
-
-
Save jFransham/f2ce3911a1abb790b185 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
__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