From: Iain Patterson Date: Fri, 22 May 2009 15:59:34 +0000 (+0100) Subject: Include SVN prompt. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=69660d7ffcf12c1da215713e613f759e4abf2bec;hp=3c2f9e59a2f2d1297ac9d05aa9c64a78d8c554e8;p=profile.git Include SVN prompt. Allow toggling SVN prompt with prompt hide|show svn. Specify depth for svn status with SVN_PS1_DEPTH. --- diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index 436cd8c..50dd723 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -16,7 +16,10 @@ # The third part of the prompt is taken from p4-completion.bashrc. # It is shown only if __ps1_p4 is 1. By default it is 0. # -# The fourth part of the prompt is the exit status of the last command. +# The fourth part of the prompt is taken from svn-completion.bashrc. +# It is shown only if __ps1_svn is 1. By default it is 0. +# +# The fifth part of the prompt is the exit status of the last command. # This part will be shown only if __ps1_user is set and the exit status is # non-zero. # @@ -44,6 +47,7 @@ case $(tput colors) in export PROMPT_OK_COLOUR="1;38;5;34" export PROMPT_FAILED_COLOUR="1;38;5;160" export GIT_COLOUR="0;38;5;33" + export SVN_COLOUR="0;38;5;127" export P4_COLOUR="0;38;5;142" ;; @@ -51,6 +55,7 @@ case $(tput colors) in export PROMPT_OK_COLOUR="1;38;5;24" export PROMPT_FAILED_COLOUR="1;38;5;48" export GIT_COLOUR="0;38;5;23" + export SVN_COLOUR="0;38;5;49" export P4_COLOUR="0;38;5;56" ;; @@ -58,6 +63,7 @@ case $(tput colors) in export PROMPT_OK_COLOUR="1;32" export PROMPT_FAILED_COLOUR="1;31" export GIT_COLOUR="0;36" + export SVN_COLOUR="0;35" export P4_COLOUR="0;33" ;; esac @@ -66,7 +72,7 @@ function __ps1() { # Default __ps1_user to 1. [ -z "$__ps1_user" ] && __ps1_user=1 - export PS1='$(__ps1_user $? \u@)\[\033[$(__ps1_col $? 2>/dev/null)m\]$(__ps1_user $? \h)\[\033[${GIT_COLOUR}m\]$(__ps1_git $? 2>/dev/null)\[\033[0m\]\[\033[${P4_COLOUR}m\]$(__ps1_p4 $? 2>/dev/null)\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' + export PS1='$(__ps1_user $? \u@)\[\033[$(__ps1_col $? 2>/dev/null)m\]$(__ps1_user $? \h)\[\033[${GIT_COLOUR}m\]$(__ps1_git $? 2>/dev/null)\[\033[0m\]\[\033[${P4_COLOUR}m\]$(__ps1_p4 $? 2>/dev/null)\[\033[0m\]\[\033[${SVN_COLOUR}m\]$(__ps1_svn $? 2>/dev/null)\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' return 0 } @@ -108,6 +114,16 @@ function __ps1_p4() { return $1 } +function __ps1_svn() { + [ "$__ps1_svn" = "1" ] || return $1 + if [ "$__ps1_user" = "1" -o "$__ps1_git" = "1" -o "$__ps1_p4" = "1" ]; then + __svn_ps1 ' %s' + else + __svn_ps1 '%s' + fi + return $1 +} + function prompt() { local blurb="Usage: prompt hide|show " diff --git a/.profile.d/svn-completion.bashrc b/.profile.d/svn-completion.bashrc new file mode 100644 index 0000000..3ccc627 --- /dev/null +++ b/.profile.d/svn-completion.bashrc @@ -0,0 +1,65 @@ +function __svn_uuid() { + svn info 2>/dev/null | sed -n 's/^Repository UUID: //p' + return $? +} + +function __svn_dir() { + local last="$1"; shift + local uuid=$(__svn_uuid) + + if [ -n "$last" -a ! "$uuid" = "$last" ]; then + echo "$OLDPWD" + return 0 + fi + last="$uuid" + + cd .. + if [ "$PWD" = "$OLDPWD" ]; then + return 1 + fi + + __svn_dir "$last" + return $? +} + +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 +}