Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't kubectl bash completion work on macOS/OS X?

I followed the instructions for installing Bash completion as given by kubectl completion -h:

  1. I installed bash-completion via Homebrew
  2. In my ~/.bashrc, I first source bash-completion then output from the completion kubectl subcommand:
    • source $(brew --prefix)/etc/bash_completion
    • source <(kubectl completion bash)

With these in place, I start up a new shell but the completion doesn't work. How do I get it working?

like image 803
Dmitry Minkovsky Avatar asked Dec 23 '22 15:12

Dmitry Minkovsky


1 Answers

Once bash-completion is installed by Homebrew, it appears that its completions need to reside in $(brew --prefix)/etc/bash_completion.d. There you'll find a lot of other completions that come bundled. To add the completion for kubectl:

$ kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl

That did the trick for me.

like image 75
Dmitry Minkovsky Avatar answered Jan 04 '23 02:01

Dmitry Minkovsky