Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ajgappmark/ce955e07579168e2ca89f48f23e9c9bd to your computer and use it in GitHub Desktop.
Save ajgappmark/ce955e07579168e2ca89f48f23e9c9bd to your computer and use it in GitHub Desktop.
Show svn info in your bash prompt
# Returns (svn:<revision>:<branch|tag>[*]) if applicable
svn_prompt() {
if [ -d ".svn" ] ; then
local branch dirty rev info=$(svn info 2>/dev/null)
branch=$(svn_parse_branch "${info}")
# Uncomment if you want to display the current revision.
#rev=$(echo "${info}" | awk '/^Revision: [0-9]+/{print $2}')
# Uncomment if you want to display whether the repo is 'dirty.' In some
# cases (on large repos) this may take a few seconds, which can
# noticeably delay your prompt after a command executes.
#[ "$(svn status)" ] && dirty='*'
if [ "$branch" != "" ] ; then
echo "(svn:${rev}:${branch}${dirty})"
fi
fi
}
# Returns the current branch or tag name from the given `svn info` output
svn_parse_branch() {
local chunk url=$(echo "$1" | awk '/^URL: .*/{print $2}')
echo ${url} | grep -q "/trunk\b"
if [ $? -eq 0 ] ; then
echo trunk
return
else
# first check /branches/releases
chunk=$(echo ${url} | grep -o "/releases.*")
if [ "${chunk}" == "" ] ; then
# then check for some other branch
chunk=$(echo ${url} | grep -o "/branches.*")
if [ "${chunk}" == "" ] ; then
# last check for a tag
chunk=$(echo ${url} | grep -o "/tags.*")
fi
fi
fi
echo ${chunk} | awk -F/ '{print $3}'
}
export PS1="\w$(svn_prompt)>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment