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

Re: Composing completions for a wrapper script

Please disregard my last e-mail, I did not do compinit.

> On 1 Nov 2021, at 09:13, Anton Suslov <anton_suslov@xxxxxx> wrote:
> Oh, thanks, that was exactly what I was looking for!
> I have considered doing something similar, but I am still a bit afraid of the completer being sufficiently smart and observing some other things and breaking.
> By the way, how do I define completion for a function?
> I tried creating a _kubectldc file in a directory in my fpath, but the completion doesn't
> work, and it doesn't seem like it even gets loaded automatically. When I do compdef
> like you suggested, everything works, but I want to do some more complex logic than it
> is nice to fit in the compdef argument. I tried doing the RTFM, but it suggests that
> proper filename and #compdef kubectldc should be enough.
>>> On 31 Oct 2021, at 22:32, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>> On Sun, Oct 31, 2021 at 6:23 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>> compdef -e 'shift words; (( CURRENT-- )); service=kubectl;
>>> words[1]=kubectl; _normal' kubectldc
>>> There is a side effect that if you try to complete the first word, it
>>> will try to complete command names. You can handle that with some
>>> extra code if you want, but at that point you should probably create a
>>> _kubectldc completer as it will become a bit unwieldy for a one-liner.
>> It's not too bad, assuming the first argument just needs ordinary
>> default completions.
>> compdef -e '((CURRENT>2)) && {
>> words[1,2]=(kubectl); (( CURRENT-- )); service=kubectl;
>> } || words[1]=:; _normal' kubectldc
>> If there is already a completion function for the DC argument, you can
>> replace "words[1]=:" with an assignment to service to select that
>> completion.

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