Skip to content

Instantly share code, notes, and snippets.

@adrianmoisey
Created November 17, 2014 07:14
Show Gist options
  • Save adrianmoisey/b1afa4c951e62999069d to your computer and use it in GitHub Desktop.
Save adrianmoisey/b1afa4c951e62999069d to your computer and use it in GitHub Desktop.
# Git me harder!
__git_ps1 ()
{
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/../.dotest" ]
then
local b="$(git symbolic-ref HEAD 2>/dev/null)"
r="|REBASING"
elif [ -d "$g/.dotest-merge" ]
then
r="|REBASING"
b="$(cat $g/.dotest-merge/head-name)"
elif [ -f "$g/MERGE_HEAD" ]
then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f $g/BISECT_LOG ]
then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
b="$(cut -c1-7 $g/HEAD)..."
fi
fi
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}$r"
else
printf " (%s)" "${b##refs/heads/}$r"
fi
fi
}
PS1="${PS1//\\w/\\w\$(__git_ps1)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment