Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Setup git-stash completion for a function: $line is wrong
- X-seq: zsh-users 22561
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Setup git-stash completion for a function: $line is wrong
- Date: Sun, 12 Mar 2017 15:27:42 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=HmsQXq+HYDVQHPEXN0oP781NSeD9e/bXqjOKXw12ans=; b=H50l6ayZrnqvvYH86u6kb1dyPBSis0BIUerY7Lmf195Dj5JIjwzrfd8VRP11qM1qNO Edj3UzIOx+b5GlBIMjTDmZNShb4gJnsRF1VuL1MsWnn6qtpW5MgCjMVFAJ6SNTMHF6ZC j+wOateYjxkOPs8bKv1Cgk1RS8jrpCuXDMEBlX4iLB6cpp78ozf8Km8+pMdAY2znh1ds QeLSUgIT3IlFvNLql2c451P4Mw8ncQ7O8+LdElBck3MTiSkGwv9XyL4Wh0nMlVab16GC 4tYAYuAT2dhXW7Skm+gTMr/8Q18k2z6nBJCX9ZysXoF3YXls3Octt/DQ96/252eKD1tW J76g==
- In-reply-to: <5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <5fe1f6a0-a0d1-9b21-310c-a3bb16aa7d18@thequod.de>
On Mar 12, 5:37pm, Daniel Hahler wrote:
}
} 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
} }
This can't be right. Because of the double quotes around the argument
of compdef -e, ${(@)words[2,-1]} will expand when complete_function
is executed, not when the compdef value is needed. Same for $(( $#*-1 ))
which by the way is the same as $(( $# - 1 )). Also as you are already
inside (( )) you don't need $(( )).
Try it this way:
complete_function() {
local f=$1; shift
compdef -e "words[1]=( ${${(qq)@}} ); (( CURRENT += $# )); _normal" $f
}
There's a bit of magic there using an extra ${...} around ${(qq)@} to
force the multi-word expansion of $@ back into a single string so that
the outer double-quotes won't split it the way "$@" is normally split.
} 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).
How would you envision this to work? How does "zsh itself" know what
someone is going to do inside a function body?
There's already (compdef cmd=service) e.g.
compdef gsta=git
for wrappers that don't insert things into their argument words to act
exactly like a pre-existing completion. Also, using an alias instead
of a function wrapper, i.e.,
alias gsta='git stash'
should "just work" because completion will expand the alias before it
builds $words and looks up the completion.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author