Last active
August 29, 2015 14:07
-
-
Save clok/0c8b83d38537d9366763 to your computer and use it in GitHub Desktop.
Add the working git/hg/svn branch to your CLI
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
# Add git branch to prompt | |
parse_git_branch () { | |
git branch 2> /dev/null | grep '\*' | sed 's#\* \(.*\)# (git::\1)#' | |
} | |
parse_svn_branch() { | |
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk '{print " (svn::"$1")" }' | |
} | |
parse_svn_url() { | |
svn info 2>/dev/null | sed -ne 's#^URL: ##p' | |
} | |
parse_svn_repository_root() { | |
svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p' | |
} | |
parse_hg_branch () { | |
hg branch 2> /dev/null | sed 's#\(.*\)# (hg::\1)#' | |
} | |
BLACK="\[\033[0;38m\]" | |
RED="\[\033[0;31m\]" | |
RED_BOLD="\[\033[01;31m\]" | |
BLUE="\[\033[01;34m\]" | |
GREEN="\[\033[0;32m\]" | |
export PS1="$BLACK\u@$RED\h $GREEN\w$RED_BOLD\$(parse_git_branch)\$(parse_svn_branch)\$(parse_hg_branch)$BLACK $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add this to your
.bashrc
or.bash_profile
to get a nice prompt output of the current working branch you are on when in a git repo. Also helpful with SVN.Looks like: