Skip to content

Instantly share code, notes, and snippets.

@gregw
Created November 24, 2019 06:15
Show Gist options
  • Save gregw/6408bcb746fa8dcebf03ecb7bcecabf5 to your computer and use it in GitHub Desktop.
Save gregw/6408bcb746fa8dcebf03ecb7bcecabf5 to your computer and use it in GitHub Desktop.
bash git prompt
# set a fancy prompt
__gitps1 () {
local b="$(__git_ps1)"
if [ -n "$b" ]
then
local c=$(git log @{u}.. --oneline 2>/dev/null | wc -l)
if [ "$c" -gt 0 ]
then
printf "%s^%d" "${b##refs/heads/}" "$c"
else
local c=$(git log ..@{u} --oneline 2>/dev/null | wc -l)
if [ "$c" -gt 0 ]
then
printf "%sv%d" "${b##refs/heads/}" "$c"
else
printf "%s" "${b##refs/heads/}"
fi
fi
fi
}
#PS1='\n\u@\h: \w$(__gitps1 "(%s)")\n[\!] '
PS1='\n\[\033[01;34m\]\u@\h\[\033[00m\]: \w$(__gitps1 "(%s)")\n[\!] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment