zsh-users
 help / color / mirror / code / Atom feed
From: Anton Suslov <anton_suslov@me.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>, mikachu@gmail.com
Subject: Re: Composing completions for a wrapper script
Date: Mon, 1 Nov 2021 09:13:47 +0200	[thread overview]
Message-ID: <C40CB8CB-FBD3-430B-9AD5-282E6E625D1E@me.com> (raw)
In-Reply-To: <CAH+w=7a==7C5KBz=rwUkaPVkZHgZjhwaPUstaA9uzFrTHV3+7w@mail.gmail.com>

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@brasslantern.com> wrote:
> 
> On Sun, Oct 31, 2021 at 6:23 AM Mikael Magnusson <mikachu@gmail.com> 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.


  reply	other threads:[~2021-11-01  7:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 22:07 Anton Suslov
2021-10-30 23:00 ` Jérémie Roquet
2021-10-31  6:14   ` Anton Suslov
2021-10-31 13:22 ` Mikael Magnusson
2021-10-31 20:32   ` Bart Schaefer
2021-11-01  7:13     ` Anton Suslov [this message]
2021-11-01  7:53       ` Anton Suslov

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=C40CB8CB-FBD3-430B-9AD5-282E6E625D1E@me.com \
    --to=anton_suslov@me.com \
    --cc=mikachu@gmail.com \
    --cc=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).