contrib/zsh_completion
changeset 1368 d1d605d1e839
parent 1365 74cf45f8bc19
child 1438 c22da894e4cc
equal deleted inserted replaced
1367:a7678cbd7c28 1368:d1d605d1e839
    14 
    14 
    15 local curcontext="$curcontext" state line
    15 local curcontext="$curcontext" state line
    16 typeset -A opt_args
    16 typeset -A opt_args
    17 local subcmds repos tags newFiles addedFiles
    17 local subcmds repos tags newFiles addedFiles
    18 
    18 
    19 tags=($(hg tags 2> /dev/null | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//
    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' \
    20 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
    21       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:]//g;'))
    21       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:]//g;'))
    22 
    22 
    23 if [[ $service == "hg" ]]; then
    23 if [[ $service == "hg" ]]; then
    24 	_arguments -C -A "-*" \
    24     _arguments -C -A "-*" \
    25 	'-R+[repository root directory]' \
    25     '-R+[repository root directory]' \
    26 	'-y[non-interactive]' \
    26     '-y[non-interactive]' \
    27 	'-v[verbose]' \
    27     '-v[verbose]' \
    28 	'-q[quiet]' \
    28     '-q[quiet]' \
    29 	'--time[time how long the command takes]' \
    29     '--time[time how long the command takes]' \
    30 	'--profile[profile]' \
    30     '--profile[profile]' \
    31 	'-h-[display help and exit]' \
    31     '-h-[display help and exit]' \
    32 	'--version-[output version information and exit]' \
    32     '--version-[output version information and exit]' \
    33     '--cwd[change working directory]:new working directory:_files -/' \
    33     '--cwd[change working directory]:new working directory:_files -/' \
    34 	'*::command:->subcmd' && return 0
    34     '*::command:->subcmd' && return 0
    35 
    35 
    36 	if (( CURRENT == 1 )); then
    36     if (( CURRENT == 1 )); then
    37 		_wanted commands expl 'hg command' compadd -a subcmds
    37         _wanted commands expl 'hg command' compadd -a subcmds
    38 		return
    38         return
    39 	fi
    39     fi
    40 	service="$words[1]"
    40     service="$words[1]"
    41 	curcontext="${curcontext%:*}=$service:"
    41     curcontext="${curcontext%:*}=$service:"
    42 fi
    42 fi
    43 
    43 
    44 case $service in
    44 case $service in
    45     (addremove)
    45     (addremove)
    46 		_arguments \
    46         _arguments \
    47         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    47         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    48         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    48         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    49         '*:directories:_files -/'  # assume they want to add/remove a dir
    49         '*:directories:_files -/'  # assume they want to add/remove a dir
    50     ;;
    50     ;;
    51 
    51 
    52     (add)
    52     (add)
    53         newFiles=( $(hg status -un) )
    53         newFiles=( $(hg status -un) )
    54 		_arguments \
    54         _arguments \
    55         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    55         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    56         '-X[exclude path in search]:dir:_files -W $(hg root) -/'
    56         '-X[exclude path in search]:dir:_files -W $(hg root) -/'
    57         _wanted files expl 'unknown files' compadd -a newFiles
    57         _wanted files expl 'unknown files' compadd -a newFiles
    58     ;;
    58     ;;
    59 
    59 
    60     (remove|rm)
    60     (remove|rm)
    61 		_arguments \
    61         _arguments \
    62         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    62         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    63         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    63         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    64         '*:file:_files'
    64         '*:file:_files'
    65     ;;
    65     ;;
    66 
    66 
    67 	(cat)
    67     (cat)
    68 		_arguments \
    68         _arguments \
    69         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    69         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    70         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    70         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    71         '-o[output to file]:file:' \
    71         '-o[output to file]:file:' \
    72         '-r[revision]:revision:($tags)' \
    72         '-r[revision]:revision:($tags)' \
    73         '*:file:_files'
    73         '*:file:_files'
    74 	;;
    74     ;;
    75 
    75 
    76 	(checkout|update|up|co)
    76     (checkout|update|up|co)
    77 		_arguments \
    77         _arguments \
    78         '-b[checkout the head of a specific branch]:tag:' \
    78         '-b[checkout the head of a specific branch]:tag:' \
    79         '-m[allow merging of conflicts]' \
    79         '-m[allow merging of conflicts]' \
    80         '-C[overwrite locally modified files]' \
    80         '-C[overwrite locally modified files]' \
    81         '*:revision:->revs'
    81         '*:revision:->revs'
    82         _wanted revs expl 'revision or tag' compadd -a tags
    82         _wanted revs expl 'revision or tag' compadd -a tags
    83 	;;
    83     ;;
    84 
    84 
    85 	(commit|ci)
    85     (commit|ci)
    86 		_arguments \
    86         _arguments \
    87         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    87         '-I[include path in search]:dir:_files -W $(hg root) -/' \
    88         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    88         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
    89 		'-A[run addremove during commit]' \
    89         '-A[run addremove during commit]' \
    90 		'-m[commit message]:string:' \
    90         '-m[commit message]:string:' \
    91 		'-d[date code]:string:' \
    91         '-d[date code]:string:' \
    92 		'-u[user]:string:' \
    92         '-u[user]:string:' \
    93         '*:file:_files'
    93         '*:file:_files'
    94 	;;
    94     ;;
    95 
    95 
    96 	(tag)
    96     (tag)
    97 		_arguments \
    97         _arguments \
    98 		'-l[make the tag local]:' \
    98         '-l[make the tag local]:' \
    99 		'-m[commit message]:string:' \
    99         '-m[commit message]:string:' \
   100 		'-d[date code]:string:' \
   100         '-d[date code]:string:' \
   101 		'-u[user]:string:' \
   101         '-u[user]:string:' \
   102         '*:name and revision:'
   102         '*:name and revision:'
   103 	;;
   103     ;;
   104 
   104 
   105 	(clone)
   105     (clone)
   106 		_arguments \
   106         _arguments \
   107 		'-U[skip update after cloning]' \
   107         '-U[skip update after cloning]' \
   108 		'-e[ssh command]:string:' \
   108         '-e[ssh command]:string:' \
   109 		'--pull[use pull protocol to copy metadata]' \
   109         '--pull[use pull protocol to copy metadata]' \
   110 		'--remotecmd[remote hg command]:command:->subcmd'
   110         '--remotecmd[remote hg command]:command:->subcmd'
   111 	;;
   111     ;;
   112 
   112 
   113 	(export)
   113     (export)
   114 		_arguments \
   114         _arguments \
   115         '-o[output to a file]:file:' \
   115         '-o[output to a file]:file:' \
   116         '-a-[tread all files as text]' \
   116         '-a-[tread all files as text]' \
   117         '*:revision:->revs'
   117         '*:revision:->revs'
   118         _wanted revs expl 'revision or tag' compadd -a tags
   118         _wanted revs expl 'revision or tag' compadd -a tags
   119 	;;
   119     ;;
   120 
   120 
   121 	(heads)
   121     (heads)
   122 		_arguments '-b[find branch info]'
   122         _arguments '-b[find branch info]'
   123 	;;
   123     ;;
   124 
   124 
   125 	(outgoing|out)
   125     (outgoing|out)
   126 		_arguments '-p[show patch]'
   126         _arguments '-p[show patch]'
   127 	;;
   127     ;;
   128 
   128 
   129 	(paths)
   129     (paths)
   130 		_arguments '*:symbolic name:(default default-push)'
   130         _arguments '*:symbolic name:(default default-push)'
   131 	;;
   131     ;;
   132 
   132 
   133 	(init)
   133     (init)
   134 		_arguments '*:new repo directory:_files -/'
   134         _arguments '*:new repo directory:_files -/'
   135     ;;
   135     ;;
   136 
   136 
   137 	(unbundle)
   137     (unbundle)
   138         _arguments '*:changegroup file:_files'
   138         _arguments '*:changegroup file:_files'
   139     ;;
   139     ;;
   140 
   140 
   141 	(manifest)
   141     (manifest)
   142 		_arguments \
   142         _arguments \
   143         '*:revision:->revs'
   143         '*:revision:->revs'
   144         _wanted revs expl 'revision or tag' compadd -a tags
   144         _wanted revs expl 'revision or tag' compadd -a tags
   145     ;;
   145     ;;
   146 
   146 
   147 	(parents)
   147     (parents)
   148 		_arguments \
   148         _arguments \
   149         '*:revision:->revs'
   149         '*:revision:->revs'
   150         _wanted revs expl 'revision or tag' compadd -a tags
   150         _wanted revs expl 'revision or tag' compadd -a tags
   151     ;;
   151     ;;
   152 
   152 
   153 	(serve)
   153     (serve)
   154         _arguments \
   154         _arguments \
   155         '-A[access log file]:log file:_files' \
   155         '-A[access log file]:log file:_files' \
   156         '-E[error log file]:log file:_files' \
   156         '-E[error log file]:log file:_files' \
   157         '-p[listen port]:listen port:' \
   157         '-p[listen port]:listen port:' \
   158         '-a[interface address]:interface address:' \
   158         '-a[interface address]:interface address:' \
   161         '-t[template directory]:template dir:_files -/' \
   161         '-t[template directory]:template dir:_files -/' \
   162         '--style[template style]:style' \
   162         '--style[template style]:style' \
   163         '-6[use IPv6 in addition to IPv4]'
   163         '-6[use IPv6 in addition to IPv4]'
   164     ;;
   164     ;;
   165 
   165 
   166 	(pull)
   166     (pull)
   167         repos=( $(hg paths | sed -e 's/^.*= //') )
   167         repos=( $(hg paths | sed -e 's/^.*= //') )
   168 		_arguments \
   168         _arguments \
   169         '-u[update working directory]' \
   169         '-u[update working directory]' \
   170         '-e[ssh command]:remote commands:' \
   170         '-e[ssh command]:remote commands:' \
   171 		'--remotecmd[remote hg command]:command:->subcmd' \
   171         '--remotecmd[remote hg command]:command:->subcmd' \
   172         '*:pull source:->repo'
   172         '*:pull source:->repo'
   173 		_wanted source expl 'source repository' compadd -a repos
   173         _wanted source expl 'source repository' compadd -a repos
   174     ;;
   174     ;;
   175 
   175 
   176 	(pull)
   176 	(push)
   177         repos=( $(hg paths | sed -e 's/^.*= //') )
   177         repos=( $(hg paths | sed -e 's/^.*= //') )
   178 		_arguments \
   178         _arguments \
   179         '-f[force push]' \
   179         '-f[force push]' \
   180         '-e[ssh command]:remote commands:' \
   180         '-e[ssh command]:remote commands:' \
   181 		'--remotecmd[remote hg command]:command:->subcmd' \
   181         '--remotecmd[remote hg command]:command:->subcmd' \
   182         '*:pull source:->repo'
   182         '*:pull source:->repo'
   183 		_wanted source expl 'source repository' compadd -a repos
   183         _wanted source expl 'source repository' compadd -a repos
   184     ;;
   184     ;;
   185 
   185 
   186 	(id|identify)
   186     (id|identify)
   187 	;;
   187     ;;
   188 
   188 
   189 	(recover)
   189     (recover)
   190 	;;
   190     ;;
   191 
   191 
   192 	(rawcommit)
   192     (rawcommit)
   193 		_arguments \
   193         _arguments \
   194         '-p[parent]:revision:($tags)' \
   194         '-p[parent]:revision:($tags)' \
   195         '-d[date]:date:' \
   195         '-d[date]:date:' \
   196         '-u[user]:user:' \
   196         '-u[user]:user:' \
   197         '-F[file list]:file list:_files' \
   197         '-F[file list]:file list:_files' \
   198         '-m[commit message]:string:' \
   198         '-m[commit message]:string:' \
   199         '-l[commit message file]:message file:_files -g *.txt' \
   199         '-l[commit message file]:message file:_files -g *.txt' \
   200         '*:files to commit:_files'
   200         '*:files to commit:_files'
   201 	;;
   201     ;;
   202 
   202 
   203 	(copy|cp)
   203     (copy|cp)
   204 		_arguments \
   204         _arguments \
   205         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   205         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   206         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   206         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   207         '-A-[record a copy after it has happened]' \
   207         '-A-[record a copy after it has happened]' \
   208         '-f[replace destination if it exists]' \
   208         '-f[replace destination if it exists]' \
   209         '-p[append source path to dest]' \
   209         '-p[append source path to dest]' \
   210         '*:destination:'
   210         '*:destination:'
   211 	;;
   211     ;;
   212 
   212 
   213 	(rename|mv)
   213     (rename|mv)
   214 		_arguments \
   214         _arguments \
   215         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   215         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   216         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   216         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   217         '-A-[record a copy after it has happened]' \
   217         '-A-[record a copy after it has happened]' \
   218         '-f[replace destination if it exists]' \
   218         '-f[replace destination if it exists]' \
   219         '-p[append source path to dest]' \
   219         '-p[append source path to dest]' \
   220         '*:destination:'
   220         '*:destination:'
   221 	;;
   221     ;;
   222 
   222 
   223 	(forget)
   223     (forget)
   224         addedFiles=( $(hg status -an) )
   224         addedFiles=( $(hg status -an) )
   225 		_arguments \
   225         _arguments \
   226         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   226         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   227         '-X[exclude path in search]:dir:_files -W $(hg root) -/'
   227         '-X[exclude path in search]:dir:_files -W $(hg root) -/'
   228         _wanted files expl 'newly added files' compadd -a addedFiles
   228         _wanted files expl 'newly added files' compadd -a addedFiles
   229 	;;
   229     ;;
   230 
   230 
   231 	(import|patch)
   231     (import|patch)
   232 		_arguments \
   232         _arguments \
   233         '-p[path strip (default: 1)]:count:' \
   233         '-p[path strip (default: 1)]:count:' \
   234         '-f[skip check for outstanding changes]' \
   234         '-f[skip check for outstanding changes]' \
   235         '-b[base path]:file:_files -W $(hg root)' \
   235         '-b[base path]:file:_files -W $(hg root)' \
   236         '*:patch file:_files'
   236         '*:patch file:_files'
   237 	;;
   237     ;;
   238 
   238 
   239 	(incoming|in)
   239     (incoming|in)
   240 		_arguments \
   240         _arguments \
   241         '-p[show patch]' \
   241         '-p[show patch]' \
   242         '*:mercurial repository:_files'
   242         '*:mercurial repository:_files'
   243 	;;
   243     ;;
   244 
   244 
   245 	(diff)
   245     (diff)
   246 		_arguments \
   246         _arguments \
   247         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   247         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   248         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   248         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   249         '-r[revision]:revision:($tags)' \
   249         '-r[revision]:revision:($tags)' \
   250         '-a-[tread all files as text]' \
   250         '-a-[tread all files as text]' \
   251         '*:file:_files'
   251         '*:file:_files'
   252 	;;
   252     ;;
   253 
   253 
   254 	(log|history)
   254     (log|history)
   255 		_arguments \
   255         _arguments \
   256         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   256         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   257         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   257         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   258         '-r[revision]:revision:($tags)' \
   258         '-r[revision]:revision:($tags)' \
   259         '-b[show branches]' \
   259         '-b[show branches]' \
   260         '-p[show patch]' \
   260         '-p[show patch]' \
   261         '*:file:_files'
   261         '*:file:_files'
   262 	;;
   262     ;;
   263 
   263 
   264 	(grep)
   264     (grep)
   265 		_arguments \
   265         _arguments \
   266         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   266         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   267         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   267         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   268         '-0[end fields with NUL]' \
   268         '-0[end fields with NUL]' \
   269         '--all[print all revisions with matches]' \
   269         '--all[print all revisions with matches]' \
   270         '-i[ignore case]' \
   270         '-i[ignore case]' \
   271         '-l[print names of files and revs with matches]' \
   271         '-l[print names of files and revs with matches]' \
   272         '-n[print line numbers]' \
   272         '-n[print line numbers]' \
   273         '-r[search in revision rev]:revision:($tags)' \
   273         '-r[search in revision rev]:revision:($tags)' \
   274         '-u[print user who made change]' \
   274         '-u[print user who made change]' \
   275         '*:search pattern, then files:_files'
   275         '*:search pattern, then files:_files'
   276 	;;
   276     ;;
   277 
   277 
   278 	(status)
   278     (status)
   279 		_arguments \
   279         _arguments \
   280         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   280         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   281         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   281         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   282         '-0[end filenames with NUL]' \
   282         '-0[end filenames with NUL]' \
   283         '-m[show only modified files]' \
   283         '-m[show only modified files]' \
   284         '-a[show only added files]' \
   284         '-a[show only added files]' \
   285         '-r[show only removed files]' \
   285         '-r[show only removed files]' \
   286         '-u[show only unknown files]' \
   286         '-u[show only unknown files]' \
   287         '-n[hide status prefix]' \
   287         '-n[hide status prefix]' \
   288         '*:search pattern, then files:_files'
   288         '*:search pattern, then files:_files'
   289 	;;
   289     ;;
   290 
   290 
   291 	(locate)
   291     (locate)
   292 		_arguments \
   292         _arguments \
   293         '-r[search in revision rev]:revision:($tags)' \
   293         '-r[search in revision rev]:revision:($tags)' \
   294         '-0[end fields with NUL]' \
   294         '-0[end fields with NUL]' \
   295         '-f[print complete paths]' \
   295         '-f[print complete paths]' \
   296         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   296         '-I[include path in search]:dir:_files -W $(hg root) -/' \
   297         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   297         '-X[exclude path in search]:dir:_files -W $(hg root) -/' \
   298         '*:search pattern:'
   298         '*:search pattern:'
   299 	;;
   299     ;;
   300 
   300 
   301 	(help)
   301     (help)
   302 		_wanted commands expl 'hg command' compadd -a subcmds
   302         _wanted commands expl 'hg command' compadd -a subcmds
   303 	;;
   303     ;;
   304 
   304 
   305     (root|undo|view|verify|version)
   305     (root|undo|view|verify|version)
   306         # no arguments for these commands
   306         # no arguments for these commands
   307     ;;
   307     ;;
   308 
   308 
   309 	(*)
   309     (*)
   310 		_message "unknown hg command completion: $service"
   310         _message "unknown hg command completion: $service"
   311 	;;
   311     ;;
   312 esac
   312 esac