contrib/zsh_completion
changeset 3491 459e7cd943d4
parent 3490 72b9a3b8bb1d
child 3492 776c317566b6
equal deleted inserted replaced
3490:72b9a3b8bb1d 3491:459e7cd943d4
    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 newFiles addedFiles includeExclude commitMessage
    17 local subcmds repos newFiles addedFiles includeExclude commitMessage
    18 local _hg_state
    18 local ridx _hgroot
    19 
    19 
       
    20 # FIXME: why isn't opt_args available?
       
    21 [[ -d .hg ]] && _hgroot="$PWD"
       
    22 ridx=$words[(i)-R]
       
    23 (( $ridx < $#words )) && _hgroot="${words[$ridx+1]}"
       
    24 
       
    25 # hg dispatch (borrowed from _cvs)
       
    26 (( $+functions[_hg_cmd] )) ||
       
    27 _hg_cmd () {
       
    28   _call_program hg hg -R "$_hgroot" "$@"
       
    29 }
       
    30 
       
    31 (( $+functions[_hg_state] )) ||
    20 _hg_state () {
    32 _hg_state () {
    21   case "$state" in
    33   case "$state" in
    22     (tags)
    34     (tags)
    23       compadd $(hg tags 2> /dev/null |
    35       compadd $(_hg_cmd tags 2> /dev/null |
    24         sed -e 's/[0-9]*:[a-f0-9]*$//; s/ *$//')
    36         sed -e 's/[0-9]*:[a-f0-9]*$//; s/ *$//')
    25     ;;
    37     ;;
    26     (qapplied)
    38     (qapplied)
    27       compadd $(hg qapplied)
    39       compadd $(_hg_cmd qapplied)
    28     ;;
    40     ;;
    29     (qunapplied)
    41     (qunapplied)
    30       compadd $(hg qunapplied)
    42       compadd $(_hg_cmd qunapplied)
    31     ;;
    43     ;;
    32   esac
    44   esac
    33 }
    45 }
    34 
    46 
    35 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
    47 subcmds=($(hg -v help | sed -e '1,/^list of commands:/d' \
    36       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
    48       -e '/^global options:/,$d' -e '/^ [^ ]/!d; s/[,:].*//g;'))
    37 
    49 
    38 # A lot of commands have these arguments
    50 # A lot of commands have these arguments
    39 includeExclude=(
    51 includeExclude=(
    40         '*-I-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
    52         '*-I-[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
    41         '*--include-[include names matching the given patterns]:dir:_files -W $(hg root) -/'
    53         '*--include-[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
    42         '*-X-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/'
    54         '*-X-[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
    43         '*--exclude-[exclude names matching the given patterns]:dir:_files -W $(hg root) -/')
    55         '*--exclude-[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
    44 
    56 
    45 styleOpts=(
    57 styleOpts=(
    46         '--style[display using template map file]:'
    58         '--style[display using template map file]:'
    47         '--template[display with template]:')
    59         '--template[display with template]:')
    48 
    60 
    83     curcontext="${curcontext%:*}=$service:"
    95     curcontext="${curcontext%:*}=$service:"
    84 fi
    96 fi
    85 
    97 
    86 case $service in
    98 case $service in
    87     (add)
    99     (add)
    88         newFiles=(${(ps:\0:)"$(hg status -0un .)"})
   100         newFiles=(${(ps:\0:)"$(_hg_cmd status -0un .)"})
    89         _arguments $includeExclude \
   101         _arguments $includeExclude \
    90         '*:file:->unknown'
   102         '*:file:->unknown'
    91         _wanted files expl 'unknown files' compadd -a newFiles
   103         _wanted files expl 'unknown files' compadd -a newFiles
    92     ;;
   104     ;;
    93 
   105 
    95         _arguments $includeExclude \
   107         _arguments $includeExclude \
    96         '*:directories:_files -/'  # assume they want to add/remove a dir
   108         '*:directories:_files -/'  # assume they want to add/remove a dir
    97     ;;
   109     ;;
    98 
   110 
    99     (forget)
   111     (forget)
   100         addedFiles=(${(ps:\0:)"$(hg status -0an .)"})
   112         addedFiles=(${(ps:\0:)"$(_hg_cmd status -0an .)"})
   101         _arguments $includeExclude  \
   113         _arguments $includeExclude  \
   102         '*:file:->added'
   114         '*:file:->added'
   103         _wanted files expl 'newly added files' compadd -a addedFiles
   115         _wanted files expl 'newly added files' compadd -a addedFiles
   104     ;;
   116     ;;
   105 
   117 
   159         '(-u)--unknown[show only unknown files]' \
   171         '(-u)--unknown[show only unknown files]' \
   160         '*:search pattern, then files:_files'
   172         '*:search pattern, then files:_files'
   161     ;;
   173     ;;
   162 
   174 
   163     (revert)
   175     (revert)
   164         addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
   176         addedFiles=(${(ps:\0:)"$(_hg_cmd status -0amrn .)"})
   165         _arguments \
   177         _arguments \
   166         '(--rev)-r[revision to revert to]:revision:->tags' \
   178         '(--rev)-r[revision to revert to]:revision:->tags' \
   167         '(-r)--rev[revision to revert to]:revision:->tags' \
   179         '(-r)--rev[revision to revert to]:revision:->tags' \
   168         '(--nonrecursive)-n[do not recurse into subdirectories]' \
   180         '(--nonrecursive)-n[do not recurse into subdirectories]' \
   169         '(-n)--nonrecursive[do not recurse into subdirectories]' \
   181         '(-n)--nonrecursive[do not recurse into subdirectories]' \
   170         '*:file:->modified'
   182         '*:file:->modified'
   171         _wanted files expl 'mofified files' compadd -a addedFiles
   183         _wanted files expl 'mofified files' compadd -a addedFiles
   172     ;;
   184     ;;
   173 
   185 
   174     (commit|ci)
   186     (commit|ci)
   175         addedFiles=(${(ps:\0:)"$(hg status -0amrn .)"})
   187         addedFiles=(${(ps:\0:)"$(_hg_cmd status -0amrn .)"})
   176         _arguments $includeExclude \
   188         _arguments $includeExclude \
   177         '(--addremove)-A[run addremove during commit]' \
   189         '(--addremove)-A[run addremove during commit]' \
   178         '(-A)--addremove[run addremove during commit]' \
   190         '(-A)--addremove[run addremove during commit]' \
   179         '(--message)-m[use <txt> as commit message]:string:' \
   191         '(--message)-m[use <txt> as commit message]:string:' \
   180         '(-m)--message[use <txt> as commit message]:string:' \
   192         '(-m)--message[use <txt> as commit message]:string:' \
   282         '*:name, then revision:->tags'
   294         '*:name, then revision:->tags'
   283     ;;
   295     ;;
   284 
   296 
   285     (clone)
   297     (clone)
   286         if (( CURRENT == 2 )); then
   298         if (( CURRENT == 2 )); then
   287             repos=( $(hg paths | sed -e 's/^.*= //') )
   299             repos=( $(_hg_cmd paths | sed -e 's/^.*= //') )
   288             _arguments \
   300             _arguments \
   289             '(--no-update)-U[do not update the new working directory]' \
   301             '(--no-update)-U[do not update the new working directory]' \
   290             '(-U)--no-update[do not update the new working directory]' \
   302             '(-U)--no-update[do not update the new working directory]' \
   291             '(--ssh)-e[specify ssh command to use]:string:' \
   303             '(--ssh)-e[specify ssh command to use]:string:' \
   292             '(-e)--ssh[specify ssh command to use]:string:' \
   304             '(-e)--ssh[specify ssh command to use]:string:' \
   343         _arguments \
   355         _arguments \
   344         '(--strip)-p[directory strip option for patch (default: 1)]:count:' \
   356         '(--strip)-p[directory strip option for patch (default: 1)]:count:' \
   345         '(-p)--strip[directory strip option for patch (default: 1)]:count:' \
   357         '(-p)--strip[directory strip option for patch (default: 1)]:count:' \
   346         '(--force)-f[skip check for outstanding uncommitted changes]' \
   358         '(--force)-f[skip check for outstanding uncommitted changes]' \
   347         '(-f)--force[skip check for outstanding uncommitted changes]' \
   359         '(-f)--force[skip check for outstanding uncommitted changes]' \
   348         '(--base)-b[base directory to read patches from]:file:_files -W $(hg root) -/' \
   360         '(--base)-b[base directory to read patches from]:file:_files -W $(_hg_cmd root) -/' \
   349         '(-b)--base[base directory to read patches from]:file:_files -W $(hg root) -/' \
   361         '(-b)--base[base directory to read patches from]:file:_files -W $(_hg_cmd root) -/' \
   350         '*:patch file:_files'
   362         '*:patch file:_files'
   351     ;;
   363     ;;
   352 
   364 
   353     (pull)
   365     (pull)
   354         repos=( $(hg paths | sed -e 's/^.*= //') )
   366         repos=( $(_hg_cmd paths | sed -e 's/^.*= //') )
   355         _arguments \
   367         _arguments \
   356         '(--update)-u[update working directory to tip after pull]' \
   368         '(--update)-u[update working directory to tip after pull]' \
   357         '(-u)--update[update working directory to tip after pull]' \
   369         '(-u)--update[update working directory to tip after pull]' \
   358         '(--ssh)-e[specify ssh command to use]:ssh command:' \
   370         '(--ssh)-e[specify ssh command to use]:ssh command:' \
   359         '(-e)--ssh[specify ssh command to use]:ssh command:' \
   371         '(-e)--ssh[specify ssh command to use]:ssh command:' \
   383         '*:revision:->revs'
   395         '*:revision:->revs'
   384         _wanted revs expl 'revision or tag' compadd -a tags
   396         _wanted revs expl 'revision or tag' compadd -a tags
   385     ;;
   397     ;;
   386 
   398 
   387     (push)
   399     (push)
   388         repos=( $(hg paths | sed -e 's/^.*= //') )
   400         repos=( $(_hg_cmd paths | sed -e 's/^.*= //') )
   389         _arguments \
   401         _arguments \
   390         '(--force)-f[force push]' \
   402         '(--force)-f[force push]' \
   391         '(-f)--force[force push]' \
   403         '(-f)--force[force push]' \
   392         '(--ssh)-e[specify ssh command to use]:ssh command:' \
   404         '(--ssh)-e[specify ssh command to use]:ssh command:' \
   393         '(-e)--ssh[specify ssh command to use]:ssh command:' \
   405         '(-e)--ssh[specify ssh command to use]:ssh command:' \
   470             {-f,--force}'[import uncommitted changes into patch]' \
   482             {-f,--force}'[import uncommitted changes into patch]' \
   471             ':patch name:'
   483             ':patch name:'
   472     ;;
   484     ;;
   473 
   485 
   474     (qpo*)
   486     (qpo*)
   475         applied=( $(hg qapplied) )
       
   476         _arguments \
   487         _arguments \
   477             (1){-a,--all}'[pop all patches]' \
   488             (1){-a,--all}'[pop all patches]' \
   478             {-f,--force}'[forget any local changes]' \
   489             {-f,--force}'[forget any local changes]' \
   479             ':applied patch:->qapplied'
   490             ':applied patch:->qapplied'
   480     ;;
   491     ;;