3

I have a ZSH completion script called

#compdef kubens
_arguments "1: :(- $(kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'))"

This provides completion to the kubens command. However if user provides a certain installation argument, the program is linked with kns name, so I am trying to provide completion for both of these commands uing the same #compdef.

How do I achieve that?

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214

1 Answers1

5

We could use the cmd=service form for the #compdef line:

#compdef kubens kns=kubens

Although we can use multiple names for the #compdef line, cmd=service forms could be used when the cmd behaves the same way as the service:

#compdef name ... [ -{p|P} pattern ... [ -N name ... ] ]

The file will be made autoloadable and the function defined in it will be called when completing names, each of which is either the name of a command whose arguments are to be completed ...
...
Each name may also be of the form ‘cmd=service’. When completing the command cmd, the function typically behaves as if the command (or special context) service was being completed instead.

-- zshcompsys(1): Completion System, INITIALIZATION, Autoloaded files, #compdef

hchbaw
  • 4,894
  • 18
  • 16
  • Thanks, it looks like this information was somewhat buried in the manual and no Google search result revealed it. I hope this question helps others. – ahmet alp balkan May 18 '17 at 05:20