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