Skip to content

Instantly share code, notes, and snippets.

@kaorimatz
Created August 8, 2012 08:31
Show Gist options
  • Save kaorimatz/3293431 to your computer and use it in GitHub Desktop.
Save kaorimatz/3293431 to your computer and use it in GitHub Desktop.
Show the branch name of the vcs
function vcs_branch {
local format
if [[ $# -lt 1 ]]; then
format="%s"
else
format=$1
fi
local branch=`_branch`
if [[ -n $branch ]]; then
printf $format $branch
fi
}
function _vcs_branch {
local dir=`pwd`
while [[ $dir != `dirname $dir` ]]; do
for vcs in git hg; do
if [[ -d "$dir/.$vcs" ]]; then
case $vcs in
git) __git_ps1 "git/%s"
;;
hg) echo "hg/`hg branch`"
;;
esac
return 0
fi
done
dir=`dirname $dir`
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment