contrib/zsh_completion
changeset 3603 ef9c515836ae
parent 3602 ec221317e018
child 3605 9d815b074dcb
equal deleted inserted replaced
3602:ec221317e018 3603:ef9c515836ae
    15 
    15 
    16 local curcontext="$curcontext" state line
    16 local curcontext="$curcontext" state line
    17 typeset -A _hg_cmd_globals
    17 typeset -A _hg_cmd_globals
    18 
    18 
    19 _hg() {
    19 _hg() {
    20   local cmd
    20   local cmd _hg_root
    21   integer i=2
    21   integer i=2
    22   _hg_cmd_globals=()
    22   _hg_cmd_globals=()
    23 
    23 
    24   while (( i < $#words ))
    24   while (( i < $#words ))
    25   do
    25   do
    26     case "$words[$i]" in
    26     case "$words[$i]" in
    27       -R|--repository|--cwd|--config)
    27       -R|--repository)
    28         # pass along arguments to hg completer
    28         _hg_root="$words[$i+1]"
    29         _hg_cmd_globals+="$words[$i]"
    29         _hg_cmd_globals+=("$words[$i]" "$_hg_root")
    30         _hg_cmd_globals+="$words[$i+1]"
       
    31         (( i += 2 ))
    30         (( i += 2 ))
    32         continue
    31         continue
    33       ;;
    32       ;;
    34       -R*)
    33       -R*)
    35         _hg_cmd_globals+="$words[$i]"
    34         _hg_cmd_globals+="$words[$i]"
       
    35         _hg_root="${words[$i]#-R}"
    36        (( i++ ))
    36        (( i++ ))
    37        continue
    37        continue
       
    38       ;;
       
    39       --cwd|--config)
       
    40         # pass along arguments to hg completer
       
    41         _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
       
    42         (( i += 2 ))
       
    43         continue
    38       ;;
    44       ;;
    39       -*)
    45       -*)
    40         # skip option
    46         # skip option
    41         (( i++ ))
    47         (( i++ ))
    42         continue
    48         continue
    89   then
    95   then
    90     _hg_cmd_${cmd}
    96     _hg_cmd_${cmd}
    91   else
    97   else
    92     # complete unknown commands normally
    98     # complete unknown commands normally
    93     _arguments -s -w : $_hg_global_opts \
    99     _arguments -s -w : $_hg_global_opts \
    94       '*:files:_files -W $(_hg_cmd root)'
   100       '*:files:_hg_files'
    95   fi
   101   fi
    96 }
   102 }
    97 
   103 
    98 _hg_cache_policy() {
   104 _hg_cache_policy() {
    99   typeset -a old
   105   typeset -a old
   152     tags+=($tag)
   158     tags+=($tag)
   153   done
   159   done
   154   (( $#tags )) && _describe -t tags 'tags' tags
   160   (( $#tags )) && _describe -t tags 'tags' tags
   155 }
   161 }
   156 
   162 
       
   163 _hg_files() {
       
   164   if [[ -n "$_hg_root" ]]
       
   165   then
       
   166     [[ -d "$_hg_root/.hg" ]] || return
       
   167     case "$_hg_root" in
       
   168       /*)
       
   169         _files -W $_hg_root
       
   170       ;;
       
   171       *)
       
   172         _files -W $PWD/$_hg_root
       
   173       ;;
       
   174     esac
       
   175   else
       
   176     _files
       
   177   fi
       
   178 }
       
   179 
   157 _hg_status() {
   180 _hg_status() {
   158   status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 . 2>/dev/null)"})
   181   status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 . 2>/dev/null)"})
   159 }
   182 }
   160 
   183 
   161 _hg_unknown() {
   184 _hg_unknown() {
   314   '(--text -a)'{-a,--text}'[treat all files as text]' \
   337   '(--text -a)'{-a,--text}'[treat all files as text]' \
   315   '(--user -u)'{-u,--user}'[list the author]' \
   338   '(--user -u)'{-u,--user}'[list the author]' \
   316   '(--date -d)'{-d,--date}'[list the date]' \
   339   '(--date -d)'{-d,--date}'[list the date]' \
   317   '(--number -n)'{-n,--number}'[list the revision number (default)]' \
   340   '(--number -n)'{-n,--number}'[list the revision number (default)]' \
   318   '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
   341   '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
   319   '*:files:_files -W $(_hg_cmd root)'
   342   '*:files:_hg_files'
   320 }
   343 }
   321 
   344 
   322 _hg_cmd_archive() {
   345 _hg_cmd_archive() {
   323   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   346   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   324   '--no-decode[do not pass files through decoders]' \
   347   '--no-decode[do not pass files through decoders]' \
   338 
   361 
   339 _hg_cmd_cat() {
   362 _hg_cmd_cat() {
   340   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   363   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   341   '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
   364   '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
   342   '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
   365   '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
   343   '*:file:_files -W $(_hg_cmd root)'
   366   '*:file:_hg_files'
   344 }
   367 }
   345 
   368 
   346 _hg_cmd_clone() {
   369 _hg_cmd_clone() {
   347   _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
   370   _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
   348   '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
   371   '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
   357   '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]'
   380   '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]'
   358   '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
   381   '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
   359   '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_file -g \*.txt' \
   382   '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_file -g \*.txt' \
   360   '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
   383   '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
   361   '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
   384   '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
   362   '*:file:_files -W $(_hg_cmd root)'
   385   '*:file:_hg_files'
   363 }
   386 }
   364 
   387 
   365 _hg_cmd_copy() {
   388 _hg_cmd_copy() {
   366   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   389   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   367   '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
   390   '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
   368   '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
   391   '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
   369   '*:file:_files -W $(_hg_cmd root)'
   392   '*:file:_hg_files'
   370 }
   393 }
   371 
   394 
   372 _hg_cmd_diff() {
   395 _hg_cmd_diff() {
   373   typeset -A opt_args
   396   typeset -A opt_args
   374   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
   397   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
   381 
   404 
   382   if [[ $state == 'diff_files' ]]
   405   if [[ $state == 'diff_files' ]]
   383   then
   406   then
   384     if [[ -n $opt_args[-r] ]]
   407     if [[ -n $opt_args[-r] ]]
   385     then
   408     then
   386       _files -W $(_hg_cmd root)
   409       _hg_files
   387     else
   410     else
   388       _hg_modified
   411       _hg_modified
   389     fi
   412     fi
   390   fi
   413   fi
   391 }
   414 }
   405   '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
   428   '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
   406   '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
   429   '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
   407   '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
   430   '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
   408   '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
   431   '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
   409   '(--user -u)'{-u,--user}'[print user who committed change]' \
   432   '(--user -u)'{-u,--user}'[print user who committed change]' \
   410   '*:search pattern:_files -W $(_hg_cmd root)'
   433   '*:search pattern:_hg_files'
   411 }
   434 }
   412 
   435 
   413 _hg_cmd_heads() {
   436 _hg_cmd_heads() {
   414   _arguments -s -w : $_hg_global_opts $_hg_style_opts \
   437   _arguments -s -w : $_hg_global_opts $_hg_style_opts \
   415   '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
   438   '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
   447 _hg_cmd_locate() {
   470 _hg_cmd_locate() {
   448   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   471   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   449   '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
   472   '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
   450   '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
   473   '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
   451   '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
   474   '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
   452   '*:search pattern:_files -W $(_hg_cmd root)'
   475   '*:search pattern:_hg_files'
   453 }
   476 }
   454 
   477 
   455 _hg_cmd_log() {
   478 _hg_cmd_log() {
   456   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
   479   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
   457   '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
   480   '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
   462   '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
   485   '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
   463   '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
   486   '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
   464   '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
   487   '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
   465   '(--patch -p)'{-p,--patch}'[show patch]' \
   488   '(--patch -p)'{-p,--patch}'[show patch]' \
   466   '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
   489   '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
   467   '*:files:_files -W $(_hg_cmd root)'
   490   '*:files:_hg_files'
   468 }
   491 }
   469 
   492 
   470 _hg_cmd_manifest() {
   493 _hg_cmd_manifest() {
   471   _arguments -s -w : $_hg_global_opts \
   494   _arguments -s -w : $_hg_global_opts \
   472   ':revision:_hg_tags'
   495   ':revision:_hg_tags'
   509 
   532 
   510 _hg_cmd_remove() {
   533 _hg_cmd_remove() {
   511   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   534   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   512   '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
   535   '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
   513   '(--force -f)'{-f,--force}'[remove file even if modified]' \
   536   '(--force -f)'{-f,--force}'[remove file even if modified]' \
   514   '*:file:_files -W $(_hg_cmd root)'
   537   '*:file:_hg_files'
   515 }
   538 }
   516 
   539 
   517 _hg_cmd_rename() {
   540 _hg_cmd_rename() {
   518   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   541   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   519   '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
   542   '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
   520   '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
   543   '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
   521   '*:file:_files -W $(_hg_cmd root)'
   544   '*:file:_hg_files'
   522 }
   545 }
   523 
   546 
   524 _hg_cmd_revert() {
   547 _hg_cmd_revert() {
   525   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   548   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
   526   '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
   549   '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
   530 
   553 
   531   if [[ $state == 'diff_files' ]]
   554   if [[ $state == 'diff_files' ]]
   532   then
   555   then
   533     if [[ -n $opt_args[-r] ]]
   556     if [[ -n $opt_args[-r] ]]
   534     then
   557     then
   535       _files -W $(_hg_cmd root)
   558       _hg_files
   536     else
   559     else
   537       typeset -a status_files
   560       typeset -a status_files
   538       _hg_status mard
   561       _hg_status mard
   539       _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
   562       _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
   540     fi
   563     fi
   655   '*:unapplied patch:_hg_qunapplied'
   678   '*:unapplied patch:_hg_qunapplied'
   656 }
   679 }
   657 
   680 
   658 _hg_cmd_qdiff() {
   681 _hg_cmd_qdiff() {
   659   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   682   _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
   660   '*:pattern:_files -W $(_hg_cmd root)'
   683   '*:pattern:_hg_files'
   661 }
   684 }
   662 
   685 
   663 _hg_cmd_qfold() {
   686 _hg_cmd_qfold() {
   664   _arguments -s -w : $_hg_global_opts $_h_commit_opts \
   687   _arguments -s -w : $_hg_global_opts $_h_commit_opts \
   665   '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
   688   '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
   722 
   745 
   723 _hg_cmd_qrefresh() {
   746 _hg_cmd_qrefresh() {
   724   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
   747   _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
   725   '(--git -g)'{-g,--git}'[use git extended diff format]' \
   748   '(--git -g)'{-g,--git}'[use git extended diff format]' \
   726   '(--short -s)'{-s,--short}'[short refresh]' \
   749   '(--short -s)'{-s,--short}'[short refresh]' \
   727   '*:files:_files -W $(_hg_cmd root)'
   750   '*:files:_hg_files'
   728 }
   751 }
   729 
   752 
   730 _hg_cmd_qrename() {
   753 _hg_cmd_qrename() {
   731   _arguments -s -w : $_hg_global_opts \
   754   _arguments -s -w : $_hg_global_opts \
   732   ':patch:_hg_qseries' \
   755   ':patch:_hg_qseries' \