Skip to content

Instantly share code, notes, and snippets.

@fabiocicerchia
Created July 23, 2012 08:43
Show Gist options
  • Save fabiocicerchia/3162657 to your computer and use it in GitHub Desktop.
Save fabiocicerchia/3162657 to your computer and use it in GitHub Desktop.
.bashrc PS1 for SVN & GIT
PS1='${debian_chroot:+($debian_chroot)}[\[\033[0;37m\]\t\[\033[00m\]] \[\033[0;94m\]\u\[\033[00m\] is `if [ \$? = 0 ]; then echo -e "\[\033[32m\]happy\[\033[00m\]"; else echo -e "\[\033[31m\]sad\[\033[00m\]"; fi` in \[\033[0;36m\]\w\[\033[00m\]$(
s=""
if [[ -d ".svn" ]] ; then
r=`svn info 2>&1 | grep "Revision: " | cut -d " " -f 2`
b=
url=`svn info 2>&1 | awk "/URL:/ {print $2}"`
if [[ $url =~ trunk ]]; then
b="trunk"
elif [[ $url =~ /branches/ ]]; then
b=`echo $url | sed -r "s/^.*\/(branches\/.*)$/\1/"`
elif [[ $url =~ /tags/ ]]; then
b=`echo $url | sed -r "s/^.*\/(tags\/.*)$/\1/"`
fi
s=" [$b:$r]"
if [ "$(svn st 2>&1)" != "" ]; then
conflict=`svn st | grep " C "`
if [ "$conflict" = "" ]; then
s=`echo -e "\[\033[0;33m\]$s\[\033[00m\]"`
else
s=`echo -e "\[\033[0;31m\]$s\[\033[00m\]"`
fi
else
s=`echo -e "\[\033[0;32m\]$s\[\033[00m\]"`
fi
else
git_output=`git status 2>&1 | grep "fatal: Not a git repository (or any of the parent directories): .git" | wc -l`
if [ "$git_output" != "1" ]; then
b=`git branch 2>&1 &>/dev/null;`
if [ $? -eq 0 ]; then
gs=`git status 2>&1 | grep "nothing to commit" > /dev/null 2>&1;`
if [ "$?" -eq "0" ]; then
s=`echo -e "\[\033[0;32m\]$(__git_ps1 " (%s)")\[\033[00m\]"`
else
# TODO: Implement conflicts check (with Red color)
s=`echo -e "\[\033[0;33m\]$(__git_ps1 " {%s}")\[\033[00m\]"`
fi
fi
fi
fi
echo -en "$s") \$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment