Skip to content

Instantly share code, notes, and snippets.

@knwang
Created December 10, 2014 01:41
Show Gist options
  • Save knwang/e940e089c92276aed390 to your computer and use it in GitHub Desktop.
Save knwang/e940e089c92276aed390 to your computer and use it in GitHub Desktop.
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$reset_color%}$(git_prompt_info)% %{$reset_color%}'
git_prompt_info () {
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
local d
local s
# Rebasing
if [ -d "$g/rebase-apply" ] ; then
if test -f "$g/rebase-apply/rebasing" ; then
r="|REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
# Interactive rebase
elif [ -f "$g/rebase-merge/interactive" ] ; then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
# Merging
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
if ! b="$(git describe --exact-match HEAD 2>/dev/null)" ; then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
# Dirty Branch
local newfile='?? '
if [ -n "$ZSH_VERSION" ]; then
newfile='\?\? '
fi
d=''
s=$(git status --porcelain 2> /dev/null)
[[ $s =~ "$newfile" ]] && d+='+'
[[ $s =~ "M " ]] && d+='*'
[[ $s =~ "D " ]] && d+='-'
if [ -n "${1-}" ]; then
printf "$1" "${b##refs/heads/}$r$d"
else
printf "(%s) " "${b##refs/heads/}$r$d"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment