Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected documentation for kubectl tab completion on Mac #14617

Merged
merged 3 commits into from
May 30, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions content/en/docs/tasks/tools/install-kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,46 +370,35 @@ However, the completion script depends on [**bash-completion**](https://github.c
You can install bash-completion with Homebrew:

```shell
brew install bash-completion@2
brew install bash-completion
```

{{< note >}}
The `@2` stands for bash-completion 2, which is required by the kubectl completion script (it doesn't work with bash-completion 1). In turn, bash-completion 2 requires Bash 4.1+, that's why you needed to upgrade Bash.
{{< /note >}}

As stated in the output of `brew install` ("Caveats" section), add the following lines to your `~/.bashrc` or `~/.bash_profile` file:

```shell
export BASH_COMPLETION_COMPAT_DIR=/usr/local/etc/bash_completion.d
[[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . /usr/local/etc/profile.d/bash_completion.sh
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
```

Reload your shell and verify that bash-completion is correctly installed by typing `type _init_completion`.
Reload your shell.

### Enable kubectl autocompletion

You now need to ensure that the kubectl completion script gets sourced in all your shell sessions. There are multiple ways in which you can do this:
If you installed kubectl with Homebrew (as explained [here](#install-with-homebrew-on-macos)), then the completion script was automatically installed to `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything.

- Source the completion script in your `~/.bashrc` file:

```shell
echo 'source <(kubectl completion bash)' >>~/.bashrc

```
If you didn't install through homebrew you now need to ensure that the kubectl completion script gets sourced in all your shell sessions as follows:
tengqm marked this conversation as resolved.
Show resolved Hide resolved

- Add the completion script to `/usr/local/etc/bash_completion.d`:

```shell
kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl
```

- If you installed kubectl with Homebrew (as explained [here](#install-with-homebrew-on-macos)), then the completion script was automatically installed to `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything.

{{< note >}}
bash-completion (if installed with Homebrew) sources all the completion scripts in the directory that is set in the `BASH_COMPLETION_COMPAT_DIR` environment variable.
bash-completion (if installed with Homebrew) sources all the completion scripts in the directory.
{{< /note >}}

All approaches are equivalent. After reloading your shell, kubectl autocompletion should be working.
After reloading your shell, kubectl autocompletion should be working.
{{% /tab %}}

{{% tab name="Zsh" %}}
Expand Down