zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Anton Suslov <anton_suslov@me.com>
Cc: zsh-users@zsh.org
Subject: Re: Composing completions for a wrapper script
Date: Sun, 31 Oct 2021 14:22:58 +0100	[thread overview]
Message-ID: <CAHYJk3QPpM8kRwxY=LTtcWQcj_jxMnX7Mr0EB1+3VxBj8jN4zQ@mail.gmail.com> (raw)
In-Reply-To: <C4958944-8A7C-4345-8C19-BC08BBE120AB@me.com>

On 10/31/21, Anton Suslov <anton_suslov@me.com> wrote:
> Hi, everyone!
>
> I am writing some wrapper functions over existing commands, e.g.
>
> kubectldc() {
>   DC="$1"
>   shift
>   KUBECONFIG="$HOME/.kube/$DC.kubeconfig" kubectl "$@"
> }
>
> Kubectl is a well-behaved command, which does have rich completion
> available. Is it possible to somehow reuse its completion for kubectldc
> command? As-is the function definition becomes a tradeoff between "using
> kubectl directly for completion but having to select config manually" and
> "using the wrapper for automatic config but no completion".

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.

-- 
Mikael Magnusson


  parent reply	other threads:[~2021-10-31 13:23 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 [this message]
2021-10-31 20:32   ` Bart Schaefer
2021-11-01  7:13     ` Anton Suslov
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='CAHYJk3QPpM8kRwxY=LTtcWQcj_jxMnX7Mr0EB1+3VxBj8jN4zQ@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=anton_suslov@me.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).