martinkaburu
martinkaburu

Reputation: 586

How to disable kubectl auto-completions on zsh

How can I disable the kubectl autocompletions functionality on zsh. I'm running on osx and the autocompletions are slow(probably because they have to call the remote cluster API) and I don't want them no more.

Upvotes: 2

Views: 1980

Answers (1)

Dawid Kruk
Dawid Kruk

Reputation: 9885

First of all, autocompletion in kubectl command is not enabled by default. You needed to enable it beforehand. To disable it would be best just to reverse the steps you took to enable it.

How to enable autocompletion for kubectl within zsh environment:


The kubectl completion script for Zsh can be generated with the command kubectl completion zsh. Sourcing the completion script in your shell enables kubectl autocompletion.

To do so in all your shell sessions, add the following to your ~/.zshrc file:

$ source <(kubectl completion zsh)

-- Kubernetes.io: Enabling shell autocompletion

Following above example:

Command $ source <(kubectl completion zsh):

  • can be run by itself in shell for autocompletion within current session
  • can be put in ~/.zshrc file to be loaded each time user logs in

After applying one of above solutions it should provide available options with TAB keypress to type into terminal like below:

somefolder% kubectl get pod[TAB PRESSED HERE!]
poddisruptionbudgets.policy     pods.metrics.k8s.io             podsecuritypolicies.policy      
pods                            podsecuritypolicies.extensions  podtemplates

How to disable autocompletion for kubectl within zsh environment:


As said above autocompletion is not enabled by default. It can be disabled:

  • when created for current session by:
    • creating a new session (example zsh)
  • when edited ~/.zshrc file by:
    • removing: source <(kubectl completion zsh) from ~/.zshrc file.
    • creating a new session (example zsh)

After that autocompletion for kubectl should not work.

Please let me know if you have any questions to that.

Upvotes: 3

Related Questions