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

Re: Composing completions for a wrapper script



On 10/31/21, Anton Suslov <anton_suslov@xxxxxx> 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




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