Created
May 11, 2012 14:51
-
-
Save khalidabuhakmeh/2660235 to your computer and use it in GitHub Desktop.
Git Prompt helper
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
# more helpful source control prompts | |
parse_git_branch () { | |
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#' | |
} | |
parse_hg_branch() { | |
hg branch 2>/dev/null | sed 's#\(.*\)# (hg::\1)#' | |
} | |
parse_svn_branch() { | |
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk '{print " (svn::"$1")" }' | |
} | |
parse_svn_url() { | |
if [ -e .svn ] ; then | |
svn info 2>/dev/null | sed -ne 's#^URL: ##p' | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$' | awk '{print " ("$1")" }' | |
fi | |
} | |
parse_svn_repository_root() { | |
if [ -e .svn ] ; then | |
svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p' | |
fi | |
} | |
parse_cvs_branch() { | |
if [ -e CVS ] ; then | |
#cat CVS/TAG | cut -c 2- 2>/dev/null | sed '#\(.*\)# (cvs::\1)#' | |
BRANCH=`cat CVS/TAG 2>/dev/null | cut -c 2- ` ; if [ "$BRANCH" != "" ] ; then echo " (cvs::$BRANCH)" ; fi | |
fi | |
} | |
get_branch_information() { | |
if [ -e .svn ] ; then | |
parse_svn_branch | |
elif [ -e CVS ] ; then | |
parse_cvs_branch | |
else | |
parse_git_branch | |
parse_hg_branch | |
fi | |
} | |
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\$(get_branch_information)$BLACK]: " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment