vcs.sh 538 Bytes
vcs() {
	local VCS REF

	git_dir() {
		[ 'true' != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ] && return 1
		REF=$(git symbolic-ref -q HEAD || git name-rev --name-only HEAD 2>/dev/null)
		REF=${REF#refs/heads/}
		VCS="git"
	}

	svn_dir() {
		local INFO
		INFO="$(svn info 2>/dev/null)" || return 1
		REF=$(echo "${INFO}" | awk '/^Repository Root/ { sub(".*/","",$0); r=$0 } /^Revision/ { sub("[^0-9]*","",$0); print r":"$0 }')
		VCS="svn"
	}

	git_dir || svn_dir

	echo "${VCS:+[${VCS}|${REF}]}"
}

# vim: set ft=sh ts=4 sw=4: