Return to Snippet

Revision: 18036
at September 22, 2009 00:01 by zingo


Initial Code
# Prompt setup, with SCM status
parse_git_branch() {
	local DIRTY STATUS
	STATUS=$(git status 2>/dev/null)
	[ $? -eq 1 ] || return
	[[ "$STATUS" == *'working directory clean'* ]] || DIRTY=' *'
	echo "($(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* //')$DIRTY)"
}

parse_svn_revision() {
	local DIRTY REV=$(svn info 2>/dev/null | grep Revision | sed -e 's/Revision: //')
	[ "$REV" ] || return
	[ "$(svn st)" ] && DIRTY=' *'
	echo "(r$REV$DIRTY)"
}

PS1='\u@\h:\W$(parse_git_branch)$(parse_svn_revision) \$ '

# alternative version of parse_svn_revision()
parse_svn_revision() {
	local REV=$(svnversion 2>/dev/null)
	[ $? -eq 0 ] || return
	[ "$REV" == 'exported' ] && return
	echo "($REV)"
}

Initial URL
http://www.entropy.ch/blog/Developer/2009/03/30/Git-and-SVN-Status-in-the-Bash-Prompt.html

Initial Description
Put this into your ~/.bashrc script and you should see the Git/SVN status in your prompt if your working directory is a sandbox.

Initial Title
Git and SVN Status in the Bash Prompt

Initial Tags
svn, Bash, git

Initial Language
Bash