Last active
October 27, 2015 16:24
-
-
Save jFransham/663bf009920d3f57f91d 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
#!/bin/bash | |
__git_ps1() { | |
if [ "$(git status -s 2>&1 1>/dev/null)" ]; then | |
return | |
fi | |
if [ -z "$(ps | grep fetch | grep -v grep)" ]; then | |
(git fetch 2>/dev/null 1>/dev/null &) > /dev/null | |
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 "\001\033[0m\002"` | |
if [ "$(git status 2>/dev/null | grep "our branch is behind 'origin/")" ]; then | |
color=`echo -e "\001\033[0;31m\002<<"` | |
elif [ "$(git status 2>/dev/null | grep "our branch and" | grep "have diverged")" ]; then | |
color=`echo -e "\001\033[1;34m\002<>"` | |
elif [ "$(git diff --name-only HEAD origin/$branch 2>/dev/null)" ]; then | |
color=`echo -e "\001\033[1;31m\002>>"` | |
else | |
color=`echo -e "\001\033[1;32m\002"` | |
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='\w$(__git_ps1) \u\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment