Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Setup git-stash completion for a function: $line is wrong



I am using a helper method to setup completion for functions that are
used as extended aliases.

  # Helper to setup completion for functions, e.g.
  # "complete_function gcf git commit --fixup" will setup completion for
  # "gcf" => "git commit --fixup".
  complete_function() {
    local f=$1; shift
    compdef -e "words=($* \"${(@)words[2,-1]}\"); ((CURRENT+=$(( $#*-1 )))); _normal" $f
  }

Example usage:
  complete_function gsta git stash

This works in general, but for the case above I am getting
"-- no argument or option --" with "gsta drop <tab>".

The reason for this is that $line in _git_stash is just (''), instead of
(drop '') (when using "git stash drop" directly).

  _git-stash () {
    local curcontext=$curcontext state line ret=1
    …
    _arguments -C \
      '*::: :->args' \
      ${save_arguments//#\(/(* } && ret=0

    if [[ -n $state ]]; then
      if (( CURRENT == 1 )); then
        …
        _describe -t commands command commands && ret=0
      else
        …
        curcontext=${curcontext%:*}-$line[1]:
        compset -n 1

        case $line[1] in

From looking at _arguments it looks like $line is managed through
"comparguments -W line opt_args", but does not seem to be documented:

  comparguments
    This  is used by the _arguments function to do the argument and
    command line parsing.  Like compdescribe it has an option -i to do
    the parsing  and  initialize some internal state and various options
    to access the state information to decide what should be completed.

Probably something else needs to be handled to setup completion in this
case (through compdef -e), or can it be made to work with _normal like
with other completions?

Additionally, I think that zsh itself should provide a way to more
easily setup completion for functions (i.e. something like my wrapper
function above).

Attachment: signature.asc
Description: OpenPGP digital signature



Messages sorted by: Reverse Date, Date, Thread, Author