zsh-users
 help / color / mirror / code / Atom feed
* Setup git-stash completion for a function: $line is wrong
@ 2017-03-12 16:37 Daniel Hahler
  2017-03-12 22:27 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Hahler @ 2017-03-12 16:37 UTC (permalink / raw)
  To: zsh-users


[-- Attachment #1.1: Type: text/plain, Size: 1911 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-21  4:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 16:37 Setup git-stash completion for a function: $line is wrong Daniel Hahler
2017-03-12 22:27 ` Bart Schaefer
2017-03-14 23:59   ` Daniel Hahler
2017-03-16 21:02     ` Bart Schaefer
2017-03-16 23:54       ` Daniel Shahaf
2017-03-21  4:42         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).