##// END OF EJS Templates
zsh: allow 'hg clone' to complete paths listed in ~/.hgrc
Steve Borho -
r1486:d7809d6e default
parent child Browse files
Show More
@@ -1,423 +1,425 b''
1 1 #compdef hg
2 2
3 3 # Zsh completion script for mercurial. Rename this file to _hg and copy
4 4 # it into your zsh function path (/usr/share/zsh/site-functions for
5 5 # instance)
6 6 #
7 7 # Copyright (C) 2005 Steve Borho
8 8 #
9 9 # This is free software; you can redistribute it and/or modify it under
10 10 # the terms of the GNU General Public License as published by the Free
11 11 # Software Foundation; either version 2 of the License, or (at your
12 12 # option) any later version.
13 13 #
14 14
15 15 local curcontext="$curcontext" state line
16 16 typeset -A opt_args
17 17 local subcmds repos tags newFiles addedFiles includeExclude
18 18
19 19 tags=($(hg tags 2> /dev/null | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//'))
20 20 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
21 21 -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
22 22
23 23 # A lot of commands have these arguments
24 24 includeExclude=(
25 25 '*-I-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
26 26 '*--include-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
27 27 '*-X-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/'
28 28 '*--exclude-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/')
29 29
30 30 if [[ $service == "hg" ]]; then
31 31 _arguments -C -A "-*" \
32 32 '(--repository)-R[repository root directory]:root:_files -/' \
33 33 '(-R)--repository[repository root directory]:root:_files -/' \
34 34 '--cwd[change working directory]:new working directory:_files -/' \
35 35 '(--noninteractive)-y[do not prompt, assume yes for any required answers]' \
36 36 '(-y)--noninteractive[do not prompt, assume yes for any required answers]' \
37 37 '(--verbose)-v[enable additional output]' \
38 38 '(-v)--verbose[enable additional output]' \
39 39 '(--quiet)-q[suppress output]' \
40 40 '(-q)--quiet[suppress output]' \
41 41 '(--help)-h[display help and exit]' \
42 42 '(-h)--help[display help and exit]' \
43 43 '--debug[debug mode]' \
44 44 '--debugger[start debugger]' \
45 45 '--traceback[print traceback on exception]' \
46 46 '--time[time how long the command takes]' \
47 47 '--profile[profile]' \
48 48 '--version[output version information and exit]' \
49 49 '*::command:->subcmd' && return 0
50 50
51 51 if (( CURRENT == 1 )); then
52 52 _wanted commands expl 'hg command' compadd -a subcmds
53 53 return
54 54 fi
55 55 service="$words[1]"
56 56 curcontext="${curcontext%:*}=$service:"
57 57 fi
58 58
59 59 case $service in
60 60 (add)
61 61 newFiles=(${(ps:\0:)"$(hg status -0un .)"})
62 62 _arguments $includeExclude \
63 63 '*:file:->unknown'
64 64 _wanted files expl 'unknown files' compadd -a newFiles
65 65 ;;
66 66
67 67 (addremove)
68 68 _arguments $includeExclude \
69 69 '*:directories:_files -/' # assume they want to add/remove a dir
70 70 ;;
71 71
72 72 (forget)
73 73 addedFiles=(${(ps:\0:)"$(hg status -0an .)"})
74 74 _arguments $includeExclude \
75 75 '*:file:->added'
76 76 _wanted files expl 'newly added files' compadd -a addedFiles
77 77 ;;
78 78
79 79 (remove|rm)
80 80 _arguments $includeExclude \
81 81 '*:file:_files'
82 82 ;;
83 83
84 84 (copy|cp)
85 85 _arguments $includeExclude \
86 86 '(--after)-A[record a copy that has already occurred]' \
87 87 '(-A)--after[record a copy that has already occurred]' \
88 88 '(--force)-f[forcibly copy over an existing managed file]' \
89 89 '(-f)--force[forcibly copy over an existing managed file]' \
90 90 '(--parents)-p[append source path to dest]' \
91 91 '(-p)--parents[append source path to dest]' \
92 92 '*:files:_files'
93 93 ;;
94 94
95 95 (rename|mv)
96 96 if (( CURRENT == 2 )); then
97 97 _arguments $includeExclude \
98 98 '(--after)-A[record a rename that has already occurred]' \
99 99 '(-A)--after[record a rename that has already occurred]' \
100 100 '(--force)-f[replace destination if it exists]' \
101 101 '(-F)--force[replace destination if it exists]' \
102 102 '(--parents)-p[append source path to dest]' \
103 103 '(-p)--parents[append source path to dest]' \
104 104 '*:files:_files'
105 105 else
106 106 _arguments '*:destination:_files'
107 107 fi
108 108 ;;
109 109
110 110 (diff)
111 111 _arguments $includeExclude \
112 112 '*-r[revision]:revision:($tags)' \
113 113 '*--rev[revision]:revision:($tags)' \
114 114 '(--text)-a[treat all files as text]' \
115 115 '(-a)--text[treat all files as text]' \
116 116 '*:file:_files'
117 117 ;;
118 118
119 119 (status)
120 120 _arguments $includeExclude \
121 121 '(--no-status)-n[hide status prefix]' \
122 122 '(-n)--no-status[hide status prefix]' \
123 123 '(--print0)-0[end filenames with NUL, for use with xargs]' \
124 124 '(-0)--print0[end filenames with NUL, for use with xargs]' \
125 125 '(--modified)-m[show only modified files]' \
126 126 '(-m)--modified[show only modified files]' \
127 127 '(--added)-a[show only added files]' \
128 128 '(-a)--added[show only added files]' \
129 129 '(--removed)-r[show only removed files]' \
130 130 '(-r)--removed[show only removed files]' \
131 131 '(--unknown)-u[show only unknown files]' \
132 132 '(-u)--unknown[show only unknown files]' \
133 133 '*:search pattern, then files:_files'
134 134 ;;
135 135
136 136 (revert)
137 137 addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
138 138 _arguments \
139 139 '(--rev)-r[revision to revert to]:revision:($tags)' \
140 140 '(-r)--rev[revision to revert to]:revision:($tags)' \
141 141 '(--nonrecursive)-n[do not recurse into subdirectories]' \
142 142 '(-n)--nonrecursive[do not recurse into subdirectories]' \
143 143 '*:file:->modified'
144 144 _wanted files expl 'mofified files' compadd -a addedFiles
145 145 ;;
146 146
147 147 (commit|ci)
148 148 addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
149 149 _arguments $includeExclude \
150 150 '(--addremove)-A[run addremove during commit]' \
151 151 '(-A)--addremove[run addremove during commit]' \
152 152 '(--message)-m[use <txt> as commit message]:string:' \
153 153 '(-m)--message[use <txt> as commit message]:string:' \
154 154 '(--logfile)-l[read commit message from <file>]:.log file:_file -g \*.txt' \
155 155 '(-l)--logfile[read commit message from <file>]:.log file:_file -g \*.txt' \
156 156 '(--date)-d[record datecode as commit date]:date code:' \
157 157 '(-d)--date[record datecode as commit date]:date code:' \
158 158 '(--user)-u[record user as commiter]:user:' \
159 159 '(-u)--user[record user as commiter]:user:' \
160 160 '*:file:->modified'
161 161 _wanted files expl 'mofified files' compadd -a addedFiles
162 162 ;;
163 163
164 164 (cat)
165 165 _arguments $includeExclude \
166 166 '(--output)-o[print output to file with formatted name]:filespec:' \
167 167 '(-o)--output[print output to file with formatted name]:filespec:' \
168 168 '(--rev)-r[revision]:revision:($tags)' \
169 169 '(-r)--rev[revision]:revision:($tags)' \
170 170 '*:file:_files'
171 171 ;;
172 172
173 173 (annotate)
174 174 _arguments $includeExclude \
175 175 '(--rev)-r[annotate the specified revision]:revision:($tags)' \
176 176 '(-r)--rev[annotate the specified revision]:revision:($tags)' \
177 177 '(--text)-a[treat all files as text]' \
178 178 '(-a)--text[treat all files as text]' \
179 179 '(--user)-u[list the author]' \
180 180 '(-u)--user[list the author]' \
181 181 '(--changeset)-c[list the changeset]' \
182 182 '(-c)--changeset[list the changeset]' \
183 183 '(--number)-n[list the revision number (default)]' \
184 184 '(-n)--number[list the revision number (default)]' \
185 185 '*:files:_files'
186 186 ;;
187 187
188 188 (grep)
189 189 _arguments $includeExclude \
190 190 '*-r[search in given revision range]:revision:($tags)' \
191 191 '*--rev[search in given revision range]:revision:($tags)' \
192 192 '--all[print all revisions with matches]' \
193 193 '(-print0)-0[end filenames with NUL, for use with xargs]' \
194 194 '(-0)--print0[end filenames with NUL, for use with xargs]' \
195 195 '(--ignore-case)-i[ignore case when matching]' \
196 196 '(-i)--ignore-case[ignore case when matching]' \
197 197 '(--files-with-matches)-l[print names of files and revs that match]' \
198 198 '(-l)--files-with-matches[print names of files and revs that match]' \
199 199 '(--line-number)-n[print matching line numbers]' \
200 200 '(-n)--line-number[print matching line numbers]' \
201 201 '(--user)-u[print user who committed change]' \
202 202 '(-u)--user[print user who committed change]' \
203 203 '*:search pattern:'
204 204 ;;
205 205
206 206 (locate)
207 207 _arguments $includeExclude \
208 208 '(--rev)-r[search repository as it stood at revision]:revision:($tags)' \
209 209 '(-r)--rev[search repository as it stood at revision]:revision:($tags)' \
210 210 '(--print0)-0[end filenames with NUL, for use with xargs]' \
211 211 '(-0)--print0[end filenames with NUL, for use with xargs]' \
212 212 '(--fullpath)-f[print complete paths]' \
213 213 '(-f)--fullpath[print complete paths]' \
214 214 '*:search pattern:'
215 215 ;;
216 216
217 217 (log|history)
218 218 _arguments $includeExclude \
219 219 '*-r[show the specified revision or range]:revision:($tags)' \
220 220 '*--rev[show the specified revision or range]:revision:($tags)' \
221 221 '(--no-merges -M --only-merges)-m[show only merge revisions]' \
222 222 '(--no-merges -M -m)--only-merges[show only merge revisions]' \
223 223 '(--only-merges -m --no-merges)-M[do not show merge revisions]' \
224 224 '(--only-merges -m -M)--no-merges[do not show merge revisions]' \
225 225 '(--keyword)-k[search for a keyword]:keyword:' \
226 226 '(-k)--keyword[search for a keyword]:keyword:' \
227 227 '(--branch)-b[show branches]' \
228 228 '(-b)--branch[show branches]' \
229 229 '(--patch)-p[show patch]' \
230 230 '(-p)--patch[show patch]' \
231 231 '*:file:_files'
232 232 ;;
233 233
234 234 (update|checkout|co)
235 235 _arguments \
236 236 '(--branch)-b[checkout the head of a specific branch]' \
237 237 '(-b)--branch[checkout the head of a specific branch]' \
238 238 '(-C --clean --merge)-m[allow merging of branches]' \
239 239 '(-C --clean -m)--merge[allow merging of branches]' \
240 240 '(-m --merge --clean)-C[overwrite locally modified files]' \
241 241 '(-m --merge -C)--clean[overwrite locally modified files]' \
242 242 '*:revision or tag:($tags)'
243 243 ;;
244 244
245 245 (tag)
246 246 _arguments \
247 247 '(--local)-l[make the tag local]' \
248 248 '(-l)--local[make the tag local]' \
249 249 '(--message)-m[message for tag commit log entry]:string:' \
250 250 '(-m)--message[message for tag commit log entry]:string:' \
251 251 '(--date)-d[record datecode as commit date]:date code:' \
252 252 '(-d)--date[record datecode as commit date]:date code:' \
253 253 '(--user)-u[record user as commiter]:user:' \
254 254 '(-u)--user[record user as commiter]:user:' \
255 255 '*:name, then revision:($tags)'
256 256 ;;
257 257
258 258 (clone)
259 259 if (( CURRENT == 2 )); then
260 repos=( $(hg paths | sed -e 's/^.*= //') )
260 261 _arguments \
261 262 '(--no-update)-U[do not update the new working directory]' \
262 263 '(-U)--no-update[do not update the new working directory]' \
263 264 '(--ssh)-e[specify ssh command to use]:string:' \
264 265 '(-e)--ssh[specify ssh command to use]:string:' \
265 266 '--pull[use pull protocol to copy metadata]' \
266 267 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
267 268 '*:local repo:_files -/'
269 _wanted source expl 'source repository' compadd -a repos
268 270 elif (( CURRENT == 3 )); then
269 271 _arguments '*:dest repo:_files -/'
270 272 fi
271 273 ;;
272 274
273 275 (rawcommit)
274 276 _arguments \
275 277 '(--parent)-p[parent revision]:revision:($tags)' \
276 278 '(-p)--parent[parent revision]:revision:($tags)' \
277 279 '(--date)-d[record datecode as commit date]:date code:' \
278 280 '(-d)--date[record datecode as commit date]:date code:' \
279 281 '(--user)-u[record user as commiter]:user:' \
280 282 '(-u)--user[record user as commiter]:user:' \
281 283 '(--message)-m[use <txt> as commit message]:string:' \
282 284 '(-m)--message[use <txt> as commit message]:string:' \
283 285 '(--logfile)-l[read commit message from <file>]:.log file:_file -g \*.txt' \
284 286 '(-l)--logfile[read commit message from <file>]:.log file:_file -g \*.txt' \
285 287 '(--files)-F[file list]:file list:_files' \
286 288 '(-F)--files[file list]:file list:_files' \
287 289 '*:files to commit:_files'
288 290 ;;
289 291
290 292 (bundle)
291 293 if (( CURRENT == 2 )); then
292 294 _arguments '*:changegroup file:_files -g \*.hg'
293 295 elif (( CURRENT == 3 )); then
294 296 _arguments '*:other repo:_files -/'
295 297 fi
296 298 ;;
297 299
298 300 (unbundle)
299 301 _arguments '*:changegroup .hg file:_files -g \*.hg'
300 302 ;;
301 303
302 304 (incoming)
303 305 _arguments \
304 306 '(--patch)-p[show patch]' \
305 307 '(-p)--patch[show patch]' \
306 308 '(--no-merges)-M[do not show merge revisions]' \
307 309 '(-M)--no-merges[do not show merge revisions]' \
308 310 '(--newest-first)-n[show newest record first]' \
309 311 '(-n)--newest-first[show newest record first]' \
310 312 '*:mercurial repository:_files -/'
311 313 ;;
312 314
313 315 (import|patch)
314 316 _arguments \
315 317 '(--strip)-p[directory strip option for patch (default: 1)]:count:' \
316 318 '(-p)--strip[directory strip option for patch (default: 1)]:count:' \
317 319 '(--force)-f[skip check for outstanding uncommitted changes]' \
318 320 '(-f)--force[skip check for outstanding uncommitted changes]' \
319 321 '(--base)-b[base directory to read patches from]:file:_files -W $(hg root) -/' \
320 322 '(-b)--base[base directory to read patches from]:file:_files -W $(hg root) -/' \
321 323 '*:patch file:_files'
322 324 ;;
323 325
324 326 (pull)
325 327 repos=( $(hg paths | sed -e 's/^.*= //') )
326 328 _arguments \
327 329 '(--update)-u[update working directory to tip after pull]' \
328 330 '(-u)--update[update working directory to tip after pull]' \
329 331 '(--ssh)-e[specify ssh command to use]:ssh command:' \
330 332 '(-e)--ssh[specify ssh command to use]:ssh command:' \
331 333 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
332 334 '*:local repo:_files -/'
333 335 _wanted source expl 'source repository' compadd -a repos
334 336 ;;
335 337
336 338 (outgoing)
337 339 _arguments \
338 340 '(--patch)-p[show patch]' \
339 341 '(-p)--patch[show patch]' \
340 342 '(--no-merges)-M[do not show merge revisions]' \
341 343 '(-M)--no-merges[do not show merge revisions]' \
342 344 '(--newest-first)-n[show newest record first]' \
343 345 '(-n)--newest-first[show newest record first]' \
344 346 '*:local repo:_files -/'
345 347 _wanted source expl 'source repository' compadd -a repos
346 348 ;;
347 349
348 350 (export)
349 351 _arguments \
350 352 '(--outout)-o[print output to file with formatted name]:filespec:' \
351 353 '(-o)--output[print output to file with formatted name]:filespec:' \
352 354 '(--text)-a[treat all files as text]' \
353 355 '(-a)--text[treat all files as text]' \
354 356 '*:revision:->revs'
355 357 _wanted revs expl 'revision or tag' compadd -a tags
356 358 ;;
357 359
358 360 (push)
359 361 repos=( $(hg paths | sed -e 's/^.*= //') )
360 362 _arguments \
361 363 '(--force)-f[force push]' \
362 364 '(-f)--force[force push]' \
363 365 '(--ssh)-e[specify ssh command to use]:ssh command:' \
364 366 '(-e)--ssh[specify ssh command to use]:ssh command:' \
365 367 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
366 368 '*:local repo:_files -/'
367 369 _wanted source expl 'source repository' compadd -a repos
368 370 ;;
369 371
370 372 (serve)
371 373 _arguments \
372 374 '(--accesslog)-A[name of access log file]:log file:_files' \
373 375 '(-A)--accesslog[name of access log file]:log file:_files' \
374 376 '(--errorlog)-E[name of error log file]:log file:_files' \
375 377 '(-E)--errorlog[name of error log file]:log file:_files' \
376 378 '(--port)-p[listen port]:listen port:' \
377 379 '(-p)--port[listen port]:listen port:' \
378 380 '(--address)-a[interface address]:interface address:' \
379 381 '(-a)--address[interface address]:interface address:' \
380 382 '(--name)-n[name to show in web pages]:repository name:' \
381 383 '(-n)--name[name to show in web pages]:repository name:' \
382 384 '(--templates)-t[web template directory]:template dir:_files -/' \
383 385 '(-t)--templates[web template directory]:template dir:_files -/' \
384 386 '--style[web template style]:style' \
385 387 '--stdio[for remote clients]' \
386 388 '(--ipv6)-6[use IPv6 in addition to IPv4]' \
387 389 '(-6)--ipv6[use IPv6 in addition to IPv4]'
388 390 ;;
389 391
390 392 (help)
391 393 _wanted commands expl 'hg command' compadd -a subcmds
392 394 ;;
393 395
394 396 (heads)
395 397 _arguments \
396 398 '(--branches)-b[find branch info]' \
397 399 '(-b)--branches[find branch info]'
398 400 ;;
399 401
400 402 (paths)
401 403 _arguments '*:symbolic name:(default default-push)'
402 404 ;;
403 405
404 406 (init)
405 407 _arguments '*:new repo directory:_files -/'
406 408 ;;
407 409
408 410 (manifest)
409 411 _arguments '*:revision:($tags)'
410 412 ;;
411 413
412 414 (parents)
413 415 _arguments '*:revision:($tags)'
414 416 ;;
415 417
416 418 (identify|recover|root|undo|view|verify|version|ct|tags)
417 419 # no arguments for these commands
418 420 ;;
419 421
420 422 (*)
421 423 _message "unknown hg command completion: $service"
422 424 ;;
423 425 esac
General Comments 0
You need to be logged in to leave comments. Login now