comparison .zfun/_subversion @ 73:b84c4cac3148

Add custom _subversion that works with svn 1.5 and later.
author Augie Fackler <durin42@gmail.com>
date Thu, 09 Apr 2009 13:24:38 -0500
parents
children
comparison
equal deleted inserted replaced
72:d23dde77450a 73:b84c4cac3148
1 #compdef svn svnadmin svnadmin-static=svnadmin
2
3 _svn () {
4 local curcontext="$curcontext" state line expl ret=1
5
6 _arguments -C \
7 '(-)--help[print help information]' \
8 '(- *)--version[print client version information]' \
9 '1: :->cmds' \
10 '*:: :->args' && ret=0
11
12 if [[ -n $state ]] && (( ! $+_svn_cmds )); then
13 typeset -gHA _svn_cmds
14 _svn_cmds=(
15 ${=${(f)${${"$(LC_ALL=C _call_program commands svn help)"#l#*Available subcommands:}%%Subversion is a tool*}}/(#s)[[:space:]]#(#b)([a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
16 )
17 fi
18
19 case $state in
20 cmds)
21 _wanted commands expl 'svn command' _svn_commands && ret=0
22 ;;
23 args)
24 local cmd args usage
25 typeset -gHA _cache_svn_status
26
27 cmd="${${(k)_svn_cmds[(R)*:$words[1]:*]}:-${(k)_svn_cmds[(i):$words[1]:]}}"
28 if (( $#cmd )); then
29 curcontext="${curcontext%:*:*}:svn-${cmd}:"
30
31 usage=${${(M)${(f)"$(LC_ALL=C _call_program options svn help $cmd)"}:#usage:*}#usage:*$cmd] }
32 args=(
33 ${=${${${(M)${(f)"$(LC_ALL=C _call_program options svn help $cmd)"##*Valid options:}:#* :*}%% #:*}/ ARG/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}
34 )
35
36 case $cmd in;
37 (add)
38 args+=(
39 '*:file:_files -g "*(^e:_svn_controlled:)"'
40 )
41 ;;
42 (commit)
43 args=(
44 ${args/(#b)(*--file*):arg:/$match[1]:file:_files}
45 '*:file:_files -g "*(e:_svn_status:)"'
46 )
47 ;;
48 (delete)
49 args+=(
50 '*:file:_files -g ".svn(/e:_svn_deletedfiles:)"'
51 )
52 ;;
53 (diff)
54 args+=(
55 '*: : _alternative "files:file:_files -g \*\(e:_svn_status:\)" "urls:URL:_svn_urls"'
56 )
57 ;;
58 (help)
59 args+=(
60 '*::sub command:_svn_commands'
61 )
62 ;;
63 (import)
64 args+=(
65 '1:project directory or import location: _alternative "files:file:_files" "urls:URL:_svn_urls"'
66 '2:import location: _alternative "files:file:_files" "urls:URL:_svn_urls"'
67 )
68 ;;
69 (log)
70 args+=(
71 '1: : _alternative "files:file:_files -g \*\(e:_svn_controlled:\)" "urls:URL:_svn_urls"'
72 '*:file:_files -g "*(e:_svn_controlled:)"'
73 )
74 ;;
75 (propset)
76 args=(
77 ':propname:(svn:ignore svn:keywords svn:executable svn:eol-style svn:mime-type svn:externals svn:needs-lock)'
78 ${args/(#b)(*--file*):arg:/$match[1]:file:_files}
79 '*:path or url: _alternative "files:file:_files" "urls:URL:_svn_urls"'
80 )
81 ;;
82 (resolved)
83 args+=(
84 '*:file:_files -g "*(e:_svn_conflicts:)"'
85 )
86 ;;
87 (revert)
88 args+=(
89 '*:file:_files -g "(.svn|*)(/e:_svn_deletedfiles:,e:_svn_status:)"'
90 )
91 ;;
92 (*)
93 case $usage in
94 *(SRC|DST|TARGET|URL*PATH)*)
95 args+=(
96 '*: : _alternative "files:file:_files" "urls:URL:_svn_urls"'
97 )
98 ;;
99 *URL*) args+=( ':URL:_svn_urls' ) ;;
100 *PATH*) args+=( '*:file:_files' ) ;;
101 esac
102 ;;
103 esac
104
105 _arguments "$args[@]" && ret=0
106
107 else
108 _message "unknown svn command: $words[1]"
109 fi
110 ;;
111 esac
112
113 return ret
114 }
115
116 _svnadmin () {
117 local curcontext="$curcontext" state line ret=1
118
119 _arguments -C \
120 '(-)--help[print help information]' \
121 '(- *)--version[print client version information]' \
122 '1: :->cmds' \
123 '*:: :->args' && ret=0
124
125 if [[ -n $state ]] && (( ! $+_svnadmin_cmds )); then
126 typeset -gHA _svnadmin_cmds
127 _svnadmin_cmds=(
128 ${=${(f)${${"$(LC_ALL=C _call_program commands svnadmin help)"#l#*Available subcommands:}}}/(#s)[[:space:]]#(#b)([-a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
129 )
130 fi
131
132 case $state in
133 cmds)
134 _wanted commands expl 'svnadmin command' _svnadmin_commands && ret=0
135 ;;
136 args)
137 local cmd args usage
138
139 cmd="${${(k)_svnadmin_cmds[(R)*:$words[1]:*]}:-${(k)_svnadmin_cmds[(i):$words[1]:]}}"
140 if (( $#cmd )); then
141 curcontext="${curcontext%:*:*}:svnadmin-${cmd}:"
142
143 usage=${${(M)${(f)"$(LC_ALL=C _call_program options svnadmin help $cmd)"}:#$cmd: usage:*}#$cmd: usage: svnadmin $cmd }
144 args=(
145 ${=${${${(M)${(f)"$(LC_ALL=C _call_program options svnadmin help $cmd)"##*Valid options:}:#*:*}%% #:*}/ ARG/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}
146 )
147 if [[ $_svnadmin_subcmd_usage == *REPOS_PATH* ]]; then
148 args+=( ":path:_files -/" )
149 elif [[ $cmd = help ]]; then
150 args+=( "*:subcommand:_svnadmin_commands" )
151 fi
152
153 _arguments "$args[@]" && ret=0
154 else
155 _message "unknown svnadmin command: $words[1]"
156 fi
157 ;;
158 esac
159
160 return ret
161 }
162
163 (( $+functions[_svn_controlled] )) ||
164 _svn_controlled() {
165 [[ -f ${(M)REPLY##*/}.svn/text-base/${REPLY##*/}.svn-base ]]
166 }
167
168 (( $+functions[_svn_conflicts] )) ||
169 _svn_conflicts() {
170 [ -n $REPLY.(mine|r<->)(N[1]) ]
171 }
172
173 (( $+functions[_svn_deletedfiles] )) ||
174 _svn_deletedfiles() {
175 # Typical usage would be _files -g '.svn(/e:_svn_deletedfiles:)'
176 local cont controlled
177 reply=( )
178 [[ $REPLY = (*/|).svn ]] || return
179 controlled=( $REPLY/text-base/*.svn-base(N:r:t) )
180 for cont in ${controlled}; do
181 [[ -e $REPLY:h/$cont ]] || reply+=( ${REPLY%.svn}$cont )
182 done
183 }
184
185 (( $+functions[_svn_status] )) ||
186 _svn_status() {
187 local dir=$REPLY:h
188 local pat="${1:-([ADMR~]|?M)}"
189
190 if (( ! $+_cache_svn_status[$dir] )); then
191 _cache_svn_status[$dir]="$(_call_program files svn status -N $dir)"
192 fi
193
194 (( ${(M)#${(f)_cache_svn_status[$dir]}:#(#s)${~pat}*$REPLY} ))
195 }
196
197 (( $+functions[_svn_urls] )) ||
198 _svn_urls() {
199 local expl remfiles remdispf remdispd suf ret=1
200
201 if [[ -prefix *: ]] && ! _urls &&
202 zstyle -T ":completion:${curcontext}:" remote-access
203 then
204 remfiles=( ${(f)"$(svn list $IPREFIX${PREFIX%%[^./][^/]#} 2>/dev/null)"} )
205 compset -P '*/'
206 compset -S '/*' || suf=file
207 remdispf=(${remfiles:#*/})
208 remdispd=(${(M)remfiles:#*/})
209 _tags files
210 while _tags; do
211 while _next_label files expl ${suf:-directory}; do
212 [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf $remdispf && ret=0
213 compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
214 ${remdispd%/} && ret=0
215 done
216 (( ret )) || return 0
217 done
218 else
219 compset -S '[^:]*'
220 _wanted url-schemas expl 'URL schema' compadd -S '' - \
221 file:// http:// https:// svn:// svn+ssh:// && ret=0
222 fi
223
224 return ret
225 }
226
227 (( $+functions[_svn_commands] )) ||
228 _svn_commands() {
229 compadd "$@" -k _svn_cmds || compadd "$@" ${(s.:.)_svn_cmds}
230 }
231
232 (( $+functions[_svnadmin_command] )) ||
233 _svnadmin_commands() {
234 compadd "$@" -k _svnadmin_cmds || compadd "$@" ${(s.:.)_svnadmin_cmds}
235 }
236
237 _subversion () {
238 case $service in
239 (svn) _svn "$@" ;;
240 (svnadmin) _svnadmin "$@" ;;
241 esac
242 }
243
244 _subversion "$@"