Skip to content

Instantly share code, notes, and snippets.

@chestozo
Created May 19, 2012 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chestozo/2731958 to your computer and use it in GitHub Desktop.
Save chestozo/2731958 to your computer and use it in GitHub Desktop.
git: display ins and outs
function __get_git_branch {
local br=""
local git="$(git symbolic-ref HEAD 2> /dev/null)"
# git
if [ -n "$git" ]; then
br="${git##refs/heads/}"
fi
echo "$br"
}
function __vcs_branch_ps1 {
local in=""
local out=""
local br="$(__get_git_branch)"
if [ -n "$br" ]; then
local upstream="$(git config branch.$br.remote)"
local upstream_branch_full="$(git config branch.$br.merge)"
local upstream_branch="${upstream_branch_full##refs/heads/}"
# Add +/- count for commits.
in=$(git log --oneline ..$upstream/$upstream_branch | wc -l | awk '{ print $1 }')
out=$(git log --oneline $upstream/$upstream_branch.. | wc -l | awk '{ print $1 }')
if [ $in -gt 0 ]; then
in=" -$in"
else
in=""
fi
if [ $out -gt 0 ]; then
out=" +$out"
else
out=""
fi
printf "(\e[0;33m%s\e[0;30m\e[0;31m%s\e[0;30m\e[0;32m%s\e[0;30m)" "${br}" "${in}" "${out}"
fi
}
#\h - host; \W - current dir name; \w - current dir path; \u - current user login
export PS1='\h:\033[38;5;21m\w\e[0m$(__vcs_branch_ps1)\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment