A small bash script that detects if your current directory is managed by Subversion or Git and shows you the branch you're in on your prompt
#!/bin/bash # # Show your SCM path/branch information on the prompt. # Currently works with subversion or git. # # OSX: set your prompt like so in ~/.profile # export PS1='\h:\W \u`source ~/scmprompt.bash`\$ ' # # The key component is the `source <path>/scmprompt.bash`. Those are backticks # surrounding the command. # # @author Ben Lake <me@benlake.org> # @license Public Domain <http://creativecommons.org/publicdomain/zero/1.0/> # # Thanks to Jon Maddox for the git branch name parsing. # (http://www.jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/) # # are we in a subversion managed directory? if [ -d ".svn" ] then # check for subversion executable S=`which svn` if [ -e "$S" ] && [ -x "$S" ] then P=`svn info | awk '/URL.*/ {sub(".*://[^/]+/", "", $2)}; /URL.*/ {print $2}'` printf ' [svn:%s]' $P fi elif [ -d ".git" ] then # check for git executable S=`which git` if [ -e "$S" ] && [ -x "$S" ] then P=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` printf ' [git:%s]' $P fi fi
Save-As: plain/text