Created
August 8, 2012 08:31
-
-
Save kaorimatz/3293431 to your computer and use it in GitHub Desktop.
Show the branch name of the vcs
This file contains hidden or 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 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