Try to line up tab header with columns.
[profile.git] / .profile.d / svn-completion.bashrc
1 # Get UUID for the working copy.
2 function __svn_uuid() {
3   svn info 2>/dev/null | sed -n 's/^Repository UUID: //p'
4   return $?
5 }
6
7 # Get SVN toplevel.
8 function __svn_dir() {
9   local last="$1"; shift
10   local uuid=$(__svn_uuid)
11
12   # Bomb out if we ended up in an unexecutable directory.
13   if [ ! -x "$PWD" ]; then
14     return 1
15   fi
16
17   # Return the last directory if we just changed and found a different repo.
18   if [ -n "$last" -a ! "$uuid" = "$last" ]; then
19     echo "$OLDPWD"
20     return 0
21   fi
22   last="$uuid"
23
24   cd ..
25
26   # Root?
27   if [ "$PWD" = "$OLDPWD" ]; then
28     return 1
29   fi
30
31   __svn_dir "$last"
32   return $?
33 }
34
35 # Find the URL for the working copy and detect if we are on trunk.
36 function __svn_url() {
37   local url=$(svn info "$1" 2>/dev/null | sed -n 's/^URL: //p')
38   [ $? -gt 0 ] && return 1
39   if [ "${url##*/}" = "trunk" ]; then
40     url="${url%%/trunk}"
41   fi
42   echo "${url##*/}"
43   return 0
44 }
45
46 function __svn_ps1() {
47   local base="$(__svn_dir)"
48   [ -z "$base" ] && return
49
50   local ps1=$(__svn_url "$base")
51   if [ $? -gt 0 ]; then
52     return
53   fi
54
55   if [ -n "${SVN_PS1_SHOWDIRTYSTATE-}" ]; then
56     local depth=
57     if [ -n "${SVN_PS1_DEPTH-}" ]; then
58       depth="--depth=$SVN_PS1_DEPTH"
59     fi
60     flags=$(svn status $depth "$base" 2>/dev/null | cut -c 1 | sort | uniq)
61     if [ -n "$flags" ]; then
62       if [ ! "${flags/[~!?]/}" = "$flags" ]; then
63         ps1="$ps1*"
64       fi
65       if [ ! "${flags/[ACDMR]/}" = "$flags" ]; then
66         ps1="$ps1+"
67       fi
68     fi
69   fi
70
71   if [ -n "${1-}" ]; then
72     printf "$1" "$ps1"
73   else
74     printf " (%s)" "$ps1"
75   fi
76 }