Skip to content

Instantly share code, notes, and snippets.

@clok
Last active August 29, 2015 14:07
Show Gist options
  • Save clok/0c8b83d38537d9366763 to your computer and use it in GitHub Desktop.
Save clok/0c8b83d38537d9366763 to your computer and use it in GitHub Desktop.
Add the working git/hg/svn branch to your CLI
# 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 $ "
@clok
Copy link
Author

clok commented Sep 30, 2014

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:

clok@level1 ~/github/typo (git::feature/add-enemies) $ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment