3 # Zsh completion script for mercurial. Rename this file to _hg and copy
4 # it into your zsh function path (/usr/share/zsh/site-functions for
7 # Copyright (C) 2005 Steve Borho
9 # This is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 2 of the License, or (at your
12 # option) any later version.
15 local curcontext="$curcontext" state line
17 local subcmds repos tags newFiles addedFiles includeExclude
19 tags=($(hg tags 2> /dev/null | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//'))
20 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
21 -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
23 # A lot of commands have these arguments
25 '*-I-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
26 '*--include-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
27 '*-X-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/'
28 '*--exclude-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/')
30 if [[ $service == "hg" ]]; then
31 _arguments -C -A "-*" \
32 '(--repository)-R[repository root directory]:root:_files -/' \
33 '(-R)--repository[repository root directory]:root:_files -/' \
34 '--cwd[change working directory]:new working directory:_files -/' \
35 '(--noninteractive)-y[do not prompt, assume yes for any required answers]' \
36 '(-y)--noninteractive[do not prompt, assume yes for any required answers]' \
37 '(--verbose)-v[enable additional output]' \
38 '(-v)--verbose[enable additional output]' \
39 '(--quiet)-q[suppress output]' \
40 '(-q)--quiet[suppress output]' \
41 '(--help)-h[display help and exit]' \
42 '(-h)--help[display help and exit]' \
43 '--debug[debug mode]' \
44 '--debugger[start debugger]' \
45 '--traceback[print traceback on exception]' \
46 '--time[time how long the command takes]' \
47 '--profile[profile]' \
48 '--version[output version information and exit]' \
49 '*::command:->subcmd' && return 0
51 if (( CURRENT == 1 )); then
52 _wanted commands expl 'hg command' compadd -a subcmds
56 curcontext="${curcontext%:*}=$service:"
61 newFiles=(${(ps:\0:)"$(hg status -0un .)"})
62 _arguments $includeExclude \
64 _wanted files expl 'unknown files' compadd -a newFiles
68 _arguments $includeExclude \
69 '*:directories:_files -/' # assume they want to add/remove a dir
73 addedFiles=(${(ps:\0:)"$(hg status -0an .)"})
74 _arguments $includeExclude \
76 _wanted files expl 'newly added files' compadd -a addedFiles
80 _arguments $includeExclude \
85 _arguments $includeExclude \
86 '(--after)-A[record a copy that has already occurred]' \
87 '(-A)--after[record a copy that has already occurred]' \
88 '(--force)-f[forcibly copy over an existing managed file]' \
89 '(-f)--force[forcibly copy over an existing managed file]' \
90 '(--parents)-p[append source path to dest]' \
91 '(-p)--parents[append source path to dest]' \
96 if (( CURRENT == 2 )); then
97 _arguments $includeExclude \
98 '(--after)-A[record a rename that has already occurred]' \
99 '(-A)--after[record a rename that has already occurred]' \
100 '(--force)-f[replace destination if it exists]' \
101 '(-F)--force[replace destination if it exists]' \
102 '(--parents)-p[append source path to dest]' \
103 '(-p)--parents[append source path to dest]' \
106 _arguments '*:destination:_files'
111 _arguments $includeExclude \
112 '*-r[revision]:revision:($tags)' \
113 '*--rev[revision]:revision:($tags)' \
114 '(--text)-a[treat all files as text]' \
115 '(-a)--text[treat all files as text]' \
120 _arguments $includeExclude \
121 '(--no-status)-n[hide status prefix]' \
122 '(-n)--no-status[hide status prefix]' \
123 '(--print0)-0[end filenames with NUL, for use with xargs]' \
124 '(-0)--print0[end filenames with NUL, for use with xargs]' \
125 '(--modified)-m[show only modified files]' \
126 '(-m)--modified[show only modified files]' \
127 '(--added)-a[show only added files]' \
128 '(-a)--added[show only added files]' \
129 '(--removed)-r[show only removed files]' \
130 '(-r)--removed[show only removed files]' \
131 '(--unknown)-u[show only unknown files]' \
132 '(-u)--unknown[show only unknown files]' \
133 '*:search pattern, then files:_files'
137 addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
139 '(--rev)-r[revision to revert to]:revision:($tags)' \
140 '(-r)--rev[revision to revert to]:revision:($tags)' \
141 '(--nonrecursive)-n[do not recurse into subdirectories]' \
142 '(-n)--nonrecursive[do not recurse into subdirectories]' \
144 _wanted files expl 'mofified files' compadd -a addedFiles
148 addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
149 _arguments $includeExclude \
150 '(--addremove)-A[run addremove during commit]' \
151 '(-A)--addremove[run addremove during commit]' \
152 '(--message)-m[use <txt> as commit message]:string:' \
153 '(-m)--message[use <txt> as commit message]:string:' \
154 '(--logfile)-l[read commit message from <file>]:.log file:_file -g \*.txt' \
155 '(-l)--logfile[read commit message from <file>]:.log file:_file -g \*.txt' \
156 '(--date)-d[record datecode as commit date]:date code:' \
157 '(-d)--date[record datecode as commit date]:date code:' \
158 '(--user)-u[record user as commiter]:user:' \
159 '(-u)--user[record user as commiter]:user:' \
161 _wanted files expl 'mofified files' compadd -a addedFiles
165 _arguments $includeExclude \
166 '(--output)-o[print output to file with formatted name]:filespec:' \
167 '(-o)--output[print output to file with formatted name]:filespec:' \
168 '(--rev)-r[revision]:revision:($tags)' \
169 '(-r)--rev[revision]:revision:($tags)' \
174 _arguments $includeExclude \
175 '(--rev)-r[annotate the specified revision]:revision:($tags)' \
176 '(-r)--rev[annotate the specified revision]:revision:($tags)' \
177 '(--text)-a[treat all files as text]' \
178 '(-a)--text[treat all files as text]' \
179 '(--user)-u[list the author]' \
180 '(-u)--user[list the author]' \
181 '(--changeset)-c[list the changeset]' \
182 '(-c)--changeset[list the changeset]' \
183 '(--number)-n[list the revision number (default)]' \
184 '(-n)--number[list the revision number (default)]' \
189 _arguments $includeExclude \
190 '*-r[search in given revision range]:revision:($tags)' \
191 '*--rev[search in given revision range]:revision:($tags)' \
192 '--all[print all revisions with matches]' \
193 '(-print0)-0[end filenames with NUL, for use with xargs]' \
194 '(-0)--print0[end filenames with NUL, for use with xargs]' \
195 '(--ignore-case)-i[ignore case when matching]' \
196 '(-i)--ignore-case[ignore case when matching]' \
197 '(--files-with-matches)-l[print names of files and revs that match]' \
198 '(-l)--files-with-matches[print names of files and revs that match]' \
199 '(--line-number)-n[print matching line numbers]' \
200 '(-n)--line-number[print matching line numbers]' \
201 '(--user)-u[print user who committed change]' \
202 '(-u)--user[print user who committed change]' \
207 _arguments $includeExclude \
208 '(--rev)-r[search repository as it stood at revision]:revision:($tags)' \
209 '(-r)--rev[search repository as it stood at revision]:revision:($tags)' \
210 '(--print0)-0[end filenames with NUL, for use with xargs]' \
211 '(-0)--print0[end filenames with NUL, for use with xargs]' \
212 '(--fullpath)-f[print complete paths]' \
213 '(-f)--fullpath[print complete paths]' \
218 _arguments $includeExclude \
219 '*-r[show the specified revision or range]:revision:($tags)' \
220 '*--rev[show the specified revision or range]:revision:($tags)' \
221 '(--no-merges -M --only-merges)-m[show only merge revisions]' \
222 '(--no-merges -M -m)--only-merges[show only merge revisions]' \
223 '(--only-merges -m --no-merges)-M[do not show merge revisions]' \
224 '(--only-merges -m -M)--no-merges[do not show merge revisions]' \
225 '(--keyword)-k[search for a keyword]:keyword:' \
226 '(-k)--keyword[search for a keyword]:keyword:' \
227 '(--branch)-b[show branches]' \
228 '(-b)--branch[show branches]' \
229 '(--patch)-p[show patch]' \
230 '(-p)--patch[show patch]' \
236 '(--branch)-b[checkout the head of a specific branch]' \
237 '(-b)--branch[checkout the head of a specific branch]' \
238 '(-C --clean --merge)-m[allow merging of branches]' \
239 '(-C --clean -m)--merge[allow merging of branches]' \
240 '(-m --merge --clean)-C[overwrite locally modified files]' \
241 '(-m --merge -C)--clean[overwrite locally modified files]' \
242 '*:revision or tag:($tags)'
247 '(--local)-l[make the tag local]' \
248 '(-l)--local[make the tag local]' \
249 '(--message)-m[message for tag commit log entry]:string:' \
250 '(-m)--message[message for tag commit log entry]:string:' \
251 '(--date)-d[record datecode as commit date]:date code:' \
252 '(-d)--date[record datecode as commit date]:date code:' \
253 '(--user)-u[record user as commiter]:user:' \
254 '(-u)--user[record user as commiter]:user:' \
255 '*:name, then revision:($tags)'
259 if (( CURRENT == 2 )); then
260 repos=( $(hg paths | sed -e 's/^.*= //') )
262 '(--no-update)-U[do not update the new working directory]' \
263 '(-U)--no-update[do not update the new working directory]' \
264 '(--ssh)-e[specify ssh command to use]:string:' \
265 '(-e)--ssh[specify ssh command to use]:string:' \
266 '--pull[use pull protocol to copy metadata]' \
267 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
268 '*:local repo:_files -/'
269 _wanted source expl 'source repository' compadd -a repos
270 elif (( CURRENT == 3 )); then
271 _arguments '*:dest repo:_files -/'
277 '(--parent)-p[parent revision]:revision:($tags)' \
278 '(-p)--parent[parent revision]:revision:($tags)' \
279 '(--date)-d[record datecode as commit date]:date code:' \
280 '(-d)--date[record datecode as commit date]:date code:' \
281 '(--user)-u[record user as commiter]:user:' \
282 '(-u)--user[record user as commiter]:user:' \
283 '(--message)-m[use <txt> as commit message]:string:' \
284 '(-m)--message[use <txt> as commit message]:string:' \
285 '(--logfile)-l[read commit message from <file>]:.log file:_file -g \*.txt' \
286 '(-l)--logfile[read commit message from <file>]:.log file:_file -g \*.txt' \
287 '(--files)-F[file list]:file list:_files' \
288 '(-F)--files[file list]:file list:_files' \
289 '*:files to commit:_files'
293 if (( CURRENT == 2 )); then
294 _arguments '*:changegroup file:_files -g \*.hg'
295 elif (( CURRENT == 3 )); then
296 _arguments '*:other repo:_files -/'
301 _arguments '*:changegroup .hg file:_files -g \*.hg'
306 '(--patch)-p[show patch]' \
307 '(-p)--patch[show patch]' \
308 '(--no-merges)-M[do not show merge revisions]' \
309 '(-M)--no-merges[do not show merge revisions]' \
310 '(--newest-first)-n[show newest record first]' \
311 '(-n)--newest-first[show newest record first]' \
312 '*:mercurial repository:_files -/'
317 '(--strip)-p[directory strip option for patch (default: 1)]:count:' \
318 '(-p)--strip[directory strip option for patch (default: 1)]:count:' \
319 '(--force)-f[skip check for outstanding uncommitted changes]' \
320 '(-f)--force[skip check for outstanding uncommitted changes]' \
321 '(--base)-b[base directory to read patches from]:file:_files -W $(hg root) -/' \
322 '(-b)--base[base directory to read patches from]:file:_files -W $(hg root) -/' \
323 '*:patch file:_files'
327 repos=( $(hg paths | sed -e 's/^.*= //') )
329 '(--update)-u[update working directory to tip after pull]' \
330 '(-u)--update[update working directory to tip after pull]' \
331 '(--ssh)-e[specify ssh command to use]:ssh command:' \
332 '(-e)--ssh[specify ssh command to use]:ssh command:' \
333 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
334 '*:local repo:_files -/'
335 _wanted source expl 'source repository' compadd -a repos
340 '(--patch)-p[show patch]' \
341 '(-p)--patch[show patch]' \
342 '(--no-merges)-M[do not show merge revisions]' \
343 '(-M)--no-merges[do not show merge revisions]' \
344 '(--newest-first)-n[show newest record first]' \
345 '(-n)--newest-first[show newest record first]' \
346 '*:local repo:_files -/'
347 _wanted source expl 'source repository' compadd -a repos
352 '(--outout)-o[print output to file with formatted name]:filespec:' \
353 '(-o)--output[print output to file with formatted name]:filespec:' \
354 '(--text)-a[treat all files as text]' \
355 '(-a)--text[treat all files as text]' \
357 _wanted revs expl 'revision or tag' compadd -a tags
361 repos=( $(hg paths | sed -e 's/^.*= //') )
363 '(--force)-f[force push]' \
364 '(-f)--force[force push]' \
365 '(--ssh)-e[specify ssh command to use]:ssh command:' \
366 '(-e)--ssh[specify ssh command to use]:ssh command:' \
367 '--remotecmd[specify hg command to run on the remote side]:remote hg:' \
368 '*:local repo:_files -/'
369 _wanted source expl 'source repository' compadd -a repos
374 '(--accesslog)-A[name of access log file]:log file:_files' \
375 '(-A)--accesslog[name of access log file]:log file:_files' \
376 '(--errorlog)-E[name of error log file]:log file:_files' \
377 '(-E)--errorlog[name of error log file]:log file:_files' \
378 '(--port)-p[listen port]:listen port:' \
379 '(-p)--port[listen port]:listen port:' \
380 '(--address)-a[interface address]:interface address:' \
381 '(-a)--address[interface address]:interface address:' \
382 '(--name)-n[name to show in web pages]:repository name:' \
383 '(-n)--name[name to show in web pages]:repository name:' \
384 '(--templates)-t[web template directory]:template dir:_files -/' \
385 '(-t)--templates[web template directory]:template dir:_files -/' \
386 '--style[web template style]:style' \
387 '--stdio[for remote clients]' \
388 '(--ipv6)-6[use IPv6 in addition to IPv4]' \
389 '(-6)--ipv6[use IPv6 in addition to IPv4]'
393 _wanted commands expl 'hg command' compadd -a subcmds
398 '(--branches)-b[find branch info]' \
399 '(-b)--branches[find branch info]'
403 _arguments '*:symbolic name:(default default-push)'
407 _arguments '*:new repo directory:_files -/'
411 _arguments '*:revision:($tags)'
415 _arguments '*:revision:($tags)'
418 (identify|recover|root|undo|view|verify|version|ct|tags)
419 # no arguments for these commands
423 _message "unknown hg command completion: $service"