Skip to content

Instantly share code, notes, and snippets.

@claussni
Created March 30, 2011 12:32
Show Gist options
  • Save claussni/894310 to your computer and use it in GitHub Desktop.
Save claussni/894310 to your computer and use it in GitHub Desktop.
Source Control Management Bash Prompt Highlighting
##
## SCM info
##
scm_info() {
local bzr_info=`bzr revno --tree 2> /dev/null`
if [ ${bzr_info} ]; then
if [ "$(bzr st -S)" ]; then
local bzr_color='\033[1;31m'
else
local bzr_color='\033[1;36m'
fi
echo -e "${bzr_color}bzr:${bzr_info}"
fi
git_info=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ "${git_info}" ]; then
if [ "$(git status -s)" ]; then
git_color='\033[1;31m'
else
git_color='\033[1;36m'
fi
echo -e "${git_color}git:${git_info}"
fi
hg_info=`hg branch 2> /dev/null`
if [ ${hg_info} ]; then
if [ "$(hg st)" ]; then
hg_color='\033[1;31m'
else
hg_color='\033[1;36m'
fi
echo -e "${hg_color}hg:${hg_info}"
fi
if [ -d ${PWD}"/.svn" ]; then
svn_info=`svn info | grep ^Revision | awk '{print $2}'`
if [ "$(svn st --ignore-externals -q)" ]; then
svn_color='\033[1;31m'
else
svn_color='\033[1;36m'
fi
echo -e "${svn_color}svn:${svn_info}"
fi
if [ -d ${PWD}"/CVS" ]; then
# if [ "$(svn st)" ]; then
# cvs_color='\033[1;31m'
# else
# cvs_color='\033[1;36m'
# fi
# echo -n "${cvs_color}cvs"
echo -e "\[\033[1;36m\]cvs"
fi
}
PS1='\n\[\033[1;32m\][\w] $(scm_info)\[\033[0m\]\n\$ '
##
## / SCM info
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment