Can i use autocomplete for kubectl in zsh?

Every day I find myself ...

$ kubectl --context=foo get pods < copy text manually > $ kubectl --context=foo logs dep1-12345678-10101 

I would like to iterate over the relevant resources using

 $ kubectl --context=foo logs dep1<TAB> 

but this does not seem to do anything with my stock setup. Any ideas?

osx 10.12.3 kubectl v1.4.5 zsh zsh 5.2 (x86_64-apple-darwin16.0)

+5
source share
2 answers

Both bash and zsh support scripts that complete the print command when you press <TAB> . This function is called Programmable copmletion, and you can find more information about it here: zsh completion .

Fortunately, you do not need to write your own script - kubectl provides it for zsh> 5.2. Try running this command: source <(kubectl completion zsh) .

Another option is to use this tool: https://github.com/mkokho/kubemrr (discalimer: I'm the author). The reason it exists is because the standard completion of the script is too slow - it may take a few seconds before the responses of the tunnels will answer all the names of the subframes. But kubemrr stores the names locally, so the answer is returned almost immediately.

+10
source

I am adding this function to my $ HOME / .zshrc.

Kubectl lazy loading function will be executed

kubectl () { if [[ -z $KUBECTL_COMPLETE ]] then source <($commands[kubectl] completion zsh) KUBECTL_COMPLETE=1 fi $commands[kubectl] $* }

-1
source

Source: https://habr.com/ru/post/1264475/


All Articles