zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Setup git-stash completion for a function: $line is wrong
Date: Mon, 20 Mar 2017 21:42:13 -0700	[thread overview]
Message-ID: <170320214213.ZM30784@torch.brasslantern.com> (raw)
In-Reply-To: <20170316235404.GA23159@fujitsu.shahaf.local2>

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.


      reply	other threads:[~2017-03-21  4:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 16:37 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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=170320214213.ZM30784@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).