Skip to content

Instantly share code, notes, and snippets.

@sdthornton
Created April 21, 2014 16:08
Show Gist options
  • Save sdthornton/11147260 to your computer and use it in GitHub Desktop.
Save sdthornton/11147260 to your computer and use it in GitHub Desktop.
parse_git_bullet ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="^On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo "•"
fi
else
return 0
fi
}
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="^On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo " (${branch} "
fi
else
return 0
fi
}
parse_git_remote ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
git_status="$(git status 2> /dev/null)"
branch_pattern="^On branch ([^${IFS}]*)"
remote_pattern="Your branch is (.*) of"
diverge_pattern="Your branch and (.*) have diverged"
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="↑"
elif [ ${BASH_REMATCH[1]} == "behind" ]]; then
remote="↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo "${remote})"
fi
else
return 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment