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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With