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

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



On Mar 16, 11:54pm, Daniel Shahaf wrote:
}
} Writing a completion function for this helper today is a little tricky,
} since 'autoload +X _git' doesn't define _git-log().  Under the proposal,
} defining completion for this helper would simply be "compdef mytig='git
} log --pretty=%H'".  (Or whatever syntax is decided on)

Doing this by edit of compdef + _dispatch would be quite messy.  However,
I think there's an easier way to go about it than the approach taken by
Daniel Hahler.

Instead of defining a function that creates compdef commands, it seems
more obvious to me to define a function that can be passed to compdef.
That is, instead of

    complete_function gsta git stash	# calls compdef

why not

    compdef '_compwrap git stash' gsta
    compdef '_compwrap git log --pretty=%H' mytig

where

    _compwrap () {
      set -- "$@" "${(@)words[2,-1]}"
      local -a words=( "$@" )
      local _comp_command _comp_command1 _comp_command2
      _set_command
      _dispatch -s "$_comp_command" \
        "$_comp_command1" "$_comp_command2" -default-
    }

Calling _dispatch directly allows the current context to remain set to
:completion::complete:gsta:* rather than change to *:git:*.  It't not
clear to me whether that's desirable.  There might be some other local
declarations needed to avoid cluttering downstream namespace in the
event that nothing is completed here, but I think you get the idea.



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