contrib/zsh_completion
changeset 3487 1b9494d2b070
parent 3482 46958e428fcd
child 3488 40fabb2a64b8
equal deleted inserted replaced
3486:fbf8320f25c8 3487:1b9494d2b070
    12 # option) any later version.
    12 # option) any later version.
    13 #
    13 #
    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 includeExclude commitMessage
    17 local subcmds repos newFiles addedFiles includeExclude commitMessage
    18 
    18 local _hg_state
    19 _mq_state () {
    19 
       
    20 _hg_state () {
    20   case "$state" in
    21   case "$state" in
       
    22     (tags)
       
    23       compadd $(hg tags 2> /dev/null |
       
    24         sed -e 's/[0-9]*:[a-f0-9]*$//; s/ *$//')
       
    25     ;;
    21     (qapplied)
    26     (qapplied)
    22       compadd $(hg qapplied)
    27       compadd $(hg qapplied)
    23     ;;
    28     ;;
    24     (qunapplied)
    29     (qunapplied)
    25       compadd $(hg qunapplied)
    30       compadd $(hg qunapplied)
    26     ;;
    31     ;;
    27   esac
    32   esac
    28 }
    33 }
    29 
    34 
    30 tags=($(hg tags 2> /dev/null | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//'))
       
    31 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
    35 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
    32       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
    36       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
    33 
    37 
    34 # A lot of commands have these arguments
    38 # A lot of commands have these arguments
    35 includeExclude=(
    39 includeExclude=(
   126         fi
   130         fi
   127     ;;
   131     ;;
   128 
   132 
   129     (diff)
   133     (diff)
   130         _arguments $includeExclude \
   134         _arguments $includeExclude \
   131         '*-r[revision]:revision:($tags)' \
   135         '*-r[revision]:revision:->tags' \
   132         '*--rev[revision]:revision:($tags)' \
   136         '*--rev[revision]:revision:->tags' \
   133         '(--text)-a[treat all files as text]' \
   137         '(--text)-a[treat all files as text]' \
   134         '(-a)--text[treat all files as text]' \
   138         '(-a)--text[treat all files as text]' \
   135         '*:file:_files'
   139         '*:file:_files'
   136     ;;
   140     ;;
   137 
   141 
   153     ;;
   157     ;;
   154 
   158 
   155     (revert)
   159     (revert)
   156         addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
   160         addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
   157         _arguments \
   161         _arguments \
   158         '(--rev)-r[revision to revert to]:revision:($tags)' \
   162         '(--rev)-r[revision to revert to]:revision:->tags' \
   159         '(-r)--rev[revision to revert to]:revision:($tags)' \
   163         '(-r)--rev[revision to revert to]:revision:->tags' \
   160         '(--nonrecursive)-n[do not recurse into subdirectories]' \
   164         '(--nonrecursive)-n[do not recurse into subdirectories]' \
   161         '(-n)--nonrecursive[do not recurse into subdirectories]' \
   165         '(-n)--nonrecursive[do not recurse into subdirectories]' \
   162         '*:file:->modified'
   166         '*:file:->modified'
   163         _wanted files expl 'mofified files' compadd -a addedFiles
   167         _wanted files expl 'mofified files' compadd -a addedFiles
   164     ;;
   168     ;;
   182 
   186 
   183     (cat)
   187     (cat)
   184         _arguments $includeExclude \
   188         _arguments $includeExclude \
   185         '(--output)-o[print output to file with formatted name]:filespec:' \
   189         '(--output)-o[print output to file with formatted name]:filespec:' \
   186         '(-o)--output[print output to file with formatted name]:filespec:' \
   190         '(-o)--output[print output to file with formatted name]:filespec:' \
   187         '(--rev)-r[revision]:revision:($tags)' \
   191         '(--rev)-r[revision]:revision:->tags' \
   188         '(-r)--rev[revision]:revision:($tags)' \
   192         '(-r)--rev[revision]:revision:->tags' \
   189         '*:file:_files'
   193         '*:file:_files'
   190     ;;
   194     ;;
   191 
   195 
   192     (annotate)
   196     (annotate)
   193         _arguments $includeExclude \
   197         _arguments $includeExclude \
   194         '(--rev)-r[annotate the specified revision]:revision:($tags)' \
   198         '(--rev)-r[annotate the specified revision]:revision:->tags' \
   195         '(-r)--rev[annotate the specified revision]:revision:($tags)' \
   199         '(-r)--rev[annotate the specified revision]:revision:->tags' \
   196         '(--text)-a[treat all files as text]' \
   200         '(--text)-a[treat all files as text]' \
   197         '(-a)--text[treat all files as text]' \
   201         '(-a)--text[treat all files as text]' \
   198         '(--user)-u[list the author]' \
   202         '(--user)-u[list the author]' \
   199         '(-u)--user[list the author]' \
   203         '(-u)--user[list the author]' \
   200         '(--changeset)-c[list the changeset]' \
   204         '(--changeset)-c[list the changeset]' \
   204         '*:files:_files'
   208         '*:files:_files'
   205     ;;
   209     ;;
   206 
   210 
   207     (grep)
   211     (grep)
   208         _arguments $includeExclude \
   212         _arguments $includeExclude \
   209         '*-r[search in given revision range]:revision:($tags)' \
   213         '*-r[search in given revision range]:revision:->tags' \
   210         '*--rev[search in given revision range]:revision:($tags)' \
   214         '*--rev[search in given revision range]:revision:->tags' \
   211         '--all[print all revisions with matches]' \
   215         '--all[print all revisions with matches]' \
   212         '(-print0)-0[end filenames with NUL, for use with xargs]' \
   216         '(-print0)-0[end filenames with NUL, for use with xargs]' \
   213         '(-0)--print0[end filenames with NUL, for use with xargs]' \
   217         '(-0)--print0[end filenames with NUL, for use with xargs]' \
   214         '(--ignore-case)-i[ignore case when matching]' \
   218         '(--ignore-case)-i[ignore case when matching]' \
   215         '(-i)--ignore-case[ignore case when matching]' \
   219         '(-i)--ignore-case[ignore case when matching]' \
   222         '*:search pattern:'
   226         '*:search pattern:'
   223     ;;
   227     ;;
   224 
   228 
   225     (locate)
   229     (locate)
   226         _arguments $includeExclude \
   230         _arguments $includeExclude \
   227         '(--rev)-r[search repository as it stood at revision]:revision:($tags)' \
   231         '(--rev)-r[search repository as it stood at revision]:revision:->tags' \
   228         '(-r)--rev[search repository as it stood at revision]:revision:($tags)' \
   232         '(-r)--rev[search repository as it stood at revision]:revision:->tags' \
   229         '(--print0)-0[end filenames with NUL, for use with xargs]' \
   233         '(--print0)-0[end filenames with NUL, for use with xargs]' \
   230         '(-0)--print0[end filenames with NUL, for use with xargs]' \
   234         '(-0)--print0[end filenames with NUL, for use with xargs]' \
   231         '(--fullpath)-f[print complete paths]' \
   235         '(--fullpath)-f[print complete paths]' \
   232         '(-f)--fullpath[print complete paths]' \
   236         '(-f)--fullpath[print complete paths]' \
   233         '*:search pattern:'
   237         '*:search pattern:'
   234     ;;
   238     ;;
   235 
   239 
   236     (log|history)
   240     (log|history)
   237         _arguments $includeExclude \
   241         _arguments $includeExclude \
   238         '*-r[show the specified revision or range]:revision:($tags)' \
   242         '*-r[show the specified revision or range]:revision:->tags' \
   239         '*--rev[show the specified revision or range]:revision:($tags)' \
   243         '*--rev[show the specified revision or range]:revision:->tags' \
   240         '(--no-merges -M --only-merges)-m[show only merge revisions]' \
   244         '(--no-merges -M --only-merges)-m[show only merge revisions]' \
   241         '(--no-merges -M -m)--only-merges[show only merge revisions]' \
   245         '(--no-merges -M -m)--only-merges[show only merge revisions]' \
   242         '(--only-merges -m --no-merges)-M[do not show merge revisions]' \
   246         '(--only-merges -m --no-merges)-M[do not show merge revisions]' \
   243         '(--only-merges -m -M)--no-merges[do not show merge revisions]' \
   247         '(--only-merges -m -M)--no-merges[do not show merge revisions]' \
   244         '(--keyword)-k[search for a keyword]:keyword:' \
   248         '(--keyword)-k[search for a keyword]:keyword:' \
   256         '(-b)--branch[checkout the head of a specific branch]' \
   260         '(-b)--branch[checkout the head of a specific branch]' \
   257         '(-C --clean --merge)-m[allow merging of branches]' \
   261         '(-C --clean --merge)-m[allow merging of branches]' \
   258         '(-C --clean -m)--merge[allow merging of branches]' \
   262         '(-C --clean -m)--merge[allow merging of branches]' \
   259         '(-m --merge --clean)-C[overwrite locally modified files]' \
   263         '(-m --merge --clean)-C[overwrite locally modified files]' \
   260         '(-m --merge -C)--clean[overwrite locally modified files]' \
   264         '(-m --merge -C)--clean[overwrite locally modified files]' \
   261         '*:revision or tag:($tags)'
   265         '*:revision or tag:->tags'
   262     ;;
   266     ;;
   263 
   267 
   264     (tag)
   268     (tag)
   265         _arguments \
   269         _arguments \
   266         '(--local)-l[make the tag local]' \
   270         '(--local)-l[make the tag local]' \
   269         '(-m)--message[message for tag commit log entry]:string:' \
   273         '(-m)--message[message for tag commit log entry]:string:' \
   270         '(--date)-d[record datecode as commit date]:date code:' \
   274         '(--date)-d[record datecode as commit date]:date code:' \
   271         '(-d)--date[record datecode as commit date]:date code:' \
   275         '(-d)--date[record datecode as commit date]:date code:' \
   272         '(--user)-u[record user as commiter]:user:' \
   276         '(--user)-u[record user as commiter]:user:' \
   273         '(-u)--user[record user as commiter]:user:' \
   277         '(-u)--user[record user as commiter]:user:' \
   274         '*:name, then revision:($tags)'
   278         '*:name, then revision:->tags'
   275     ;;
   279     ;;
   276 
   280 
   277     (clone)
   281     (clone)
   278         if (( CURRENT == 2 )); then
   282         if (( CURRENT == 2 )); then
   279             repos=( $(hg paths | sed -e 's/^.*= //') )
   283             repos=( $(hg paths | sed -e 's/^.*= //') )
   291         fi
   295         fi
   292     ;;
   296     ;;
   293 
   297 
   294     (rawcommit)
   298     (rawcommit)
   295         _arguments \
   299         _arguments \
   296         '(--parent)-p[parent revision]:revision:($tags)' \
   300         '(--parent)-p[parent revision]:revision:->tags' \
   297         '(-p)--parent[parent revision]:revision:($tags)' \
   301         '(-p)--parent[parent revision]:revision:->tags' \
   298         '(--date)-d[record datecode as commit date]:date code:' \
   302         '(--date)-d[record datecode as commit date]:date code:' \
   299         '(-d)--date[record datecode as commit date]:date code:' \
   303         '(-d)--date[record datecode as commit date]:date code:' \
   300         '(--user)-u[record user as commiter]:user:' \
   304         '(--user)-u[record user as commiter]:user:' \
   301         '(-u)--user[record user as commiter]:user:' \
   305         '(-u)--user[record user as commiter]:user:' \
   302         '(--message)-m[use <txt> as commit message]:string:' \
   306         '(--message)-m[use <txt> as commit message]:string:' \
   425     (init)
   429     (init)
   426         _arguments '*:new repo directory:_files -/'
   430         _arguments '*:new repo directory:_files -/'
   427     ;;
   431     ;;
   428 
   432 
   429     (manifest)
   433     (manifest)
   430         _arguments '*:revision:($tags)'
   434         _arguments '*:revision:->tags'
   431     ;;
   435     ;;
   432 
   436 
   433     (parents)
   437     (parents)
   434         _arguments '*:revision:($tags)'
   438         _arguments '*:revision:->tags'
   435     ;;
   439     ;;
   436 
   440 
   437     (identify|recover|root|undo|view|verify|version|ct|tags)
   441     (identify|recover|root|undo|view|verify|version|ct|tags)
   438         # no arguments for these commands
   442         # no arguments for these commands
   439     ;;
   443     ;;
   442     (qdel*|qrm|qrem*)
   446     (qdel*|qrm|qrem*)
   443         _arguments \
   447         _arguments \
   444             {-k,--keep}'[keep patch file]' \
   448             {-k,--keep}'[keep patch file]' \
   445             {-r,--rev}'[revision]:applied patch:->qapplied' \
   449             {-r,--rev}'[revision]:applied patch:->qapplied' \
   446             '*:unapplied patches:->qunapplied'
   450             '*:unapplied patches:->qunapplied'
   447         _mq_state
       
   448     ;;
   451     ;;
   449 
   452 
   450     (qnew)
   453     (qnew)
   451         _arguments $commitMessage \
   454         _arguments $commitMessage \
   452             {-f,--force}'[import uncommitted changes into patch]' \
   455             {-f,--force}'[import uncommitted changes into patch]' \
   457         applied=( $(hg qapplied) )
   460         applied=( $(hg qapplied) )
   458         _arguments \
   461         _arguments \
   459             (1){-a,--all}'[pop all patches]' \
   462             (1){-a,--all}'[pop all patches]' \
   460             {-f,--force}'[forget any local changes]' \
   463             {-f,--force}'[forget any local changes]' \
   461             ':applied patch:->qapplied'
   464             ':applied patch:->qapplied'
   462         _mq_state
       
   463     ;;
   465     ;;
   464 
   466 
   465     (qpu*)
   467     (qpu*)
   466         _arguments \
   468         _arguments \
   467             (1){-a,--all}'[apply all patches]' \
   469             (1){-a,--all}'[apply all patches]' \
   468             {-f,--force}'[apply if the patch has rejects]' \
   470             {-f,--force}'[apply if the patch has rejects]' \
   469             ':unapplied patch:->qunapplied'
   471             ':unapplied patch:->qunapplied'
   470         _mq_state
       
   471     ;;
   472     ;;
   472     (qref*)
   473     (qref*)
   473         _arguments $commitMessage $includeExclude \
   474         _arguments $commitMessage $includeExclude \
   474             {-g,--git}'[use git extended diff format]' \
   475             {-g,--git}'[use git extended diff format]' \
   475             {-s,--short}'[short refresh]'
   476             {-s,--short}'[short refresh]'
   477 
   478 
   478     (*)
   479     (*)
   479         _message "unknown hg command completion: $service"
   480         _message "unknown hg command completion: $service"
   480     ;;
   481     ;;
   481 esac
   482 esac
       
   483 
       
   484 _hg_state