-
-
Save mfa/227894 to your computer and use it in GitHub Desktop.
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
# version for bash 2.03 | |
# no use of =~ and BASH_REMATCH allowed | |
function parse_git_branch { | |
if [[ `uname -s` == "SunOS" ]]; then | |
return 1 | |
fi | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
git_status="$(git status 2> /dev/null)" | |
remote_pattern="# Your branch is " | |
diverge_pattern="have diverged" | |
if echo ${git_status} | grep -qv "working directory clean"; then | |
state="*" | |
fi | |
# add an else if or two here if you want to get more specific | |
if echo ${git_status} | grep -q "${remote_pattern}"; then | |
if echo ${git_status} | grep -q "ahead" ; then | |
remote="↑" | |
else | |
remote="↓" | |
fi | |
fi | |
if echo ${git_status} | grep -q "${diverge_pattern}"; then | |
remote="↕" | |
fi | |
branch=`echo ${git_status} | grep -v "Not currently on any branch" | head -n1 | sed -e 's/^\# On branch \([a-zA-Z0-9\-]*\).*$/\1/'` | |
echo "[${branch}${state}${remote}] " | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment