Created
May 19, 2012 18:57
-
-
Save chestozo/2731958 to your computer and use it in GitHub Desktop.
git: display ins and outs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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