From: Daniel Hahler <genml+zsh-workers@thequod.de>
To: zsh-users@zsh.org
Subject: Setup git-stash completion for a function: $line is wrong
Date: Sun, 12 Mar 2017 17:37:43 +0100 [thread overview]
Message-ID: <5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de> (raw)
[-- 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 --]
next reply other threads:[~2017-03-12 16:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-12 16:37 Daniel Hahler [this message]
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
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=5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de \
--to=genml+zsh-workers@thequod.de \
--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).