# Get UUID for the working copy. function __svn_uuid() { svn info 2>/dev/null | sed -n 's/^Repository UUID: //p' return $? } # Get SVN toplevel. function __svn_dir() { local last="$1"; shift local uuid=$(__svn_uuid) # Bomb out if we ended up in an unexecutable directory. if [ ! -x "$PWD" ]; then return 1 fi # Return the last directory if we just changed and found a different repo. if [ -n "$last" -a ! "$uuid" = "$last" ]; then echo "$OLDPWD" return 0 fi last="$uuid" cd .. # Root? if [ "$PWD" = "$OLDPWD" ]; then return 1 fi __svn_dir "$last" return $? } # Find the URL for the working copy and detect if we are on trunk. function __svn_url() { local url=$(svn info "$1" 2>/dev/null | sed -n 's/^URL: //p') [ $? -gt 0 ] && return 1 if [ "${url##*/}" = "trunk" ]; then url="${url%%/trunk}" fi echo "${url##*/}" return 0 } function __svn_ps1() { local base="$(__svn_dir)" [ -z "$base" ] && return local ps1=$(__svn_url "$base") if [ $? -gt 0 ]; then return fi if [ -n "${SVN_PS1_SHOWDIRTYSTATE-}" ]; then local depth= if [ -n "${SVN_PS1_DEPTH-}" ]; then depth="--depth=$SVN_PS1_DEPTH" fi flags=$(svn status $depth "$base" 2>/dev/null | cut -c 1 | sort | uniq) if [ -n "$flags" ]; then if [ ! "${flags/[~!?]/}" = "$flags" ]; then ps1="$ps1*" fi if [ ! "${flags/[ACDMR]/}" = "$flags" ]; then ps1="$ps1+" fi fi fi if [ -n "${1-}" ]; then printf "$1" "$ps1" else printf " (%s)" "$ps1" fi }