87e3291aaa
* top-level tags and change to included files * revert content to main windows page * include gcloud and update toc * add leading blank line * add text to avoid YAML error from Netlify * remove YAML delimiter error * removed redundant weight key * add front matter and toc shortcode * test to see if toc is fixed in included page * update macos toc to show difference * use static toc instead of shortcode * uniqueness for gcloud install headers * Move to model suggested in https://github.com/kubernetes/website/pull/26682#discussion_r585091797 * correct link to included/install-kubectl-gcloud.md * correction of links to per-OS pages * try a different way to use path to per-OS links * correction of brainfart * remove .md from link destination for per-OS pages * modify how auto-competion steps are displayed * remove redundant file * correction of include - change % to < * remove closing tag as not needed * try and hide this directory from the ToC on the left * remove erroneous "include=" * addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586325123 * addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586326346 * addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586326604 * addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586327212 * https://github.com/kubernetes/website/pull/26682#discussion_r586327856 * consistent verb usage as per feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586328497 * update redirects as existing page is being deleted
55 lines
2.2 KiB
Markdown
55 lines
2.2 KiB
Markdown
---
|
|
title: "bash auto-completion on Linux"
|
|
description: "Some optional configuration for bash auto-completion on Linux."
|
|
headless: true
|
|
---
|
|
|
|
### Introduction
|
|
|
|
The kubectl completion script for Bash can be generated with the command `kubectl completion bash`. Sourcing the completion script in your shell enables kubectl autocompletion.
|
|
|
|
However, the completion script depends on [**bash-completion**](https://github.com/scop/bash-completion), which means that you have to install this software first (you can test if you have bash-completion already installed by running `type _init_completion`).
|
|
|
|
### Install bash-completion
|
|
|
|
bash-completion is provided by many package managers (see [here](https://github.com/scop/bash-completion#installation)). You can install it with `apt-get install bash-completion` or `yum install bash-completion`, etc.
|
|
|
|
The above commands create `/usr/share/bash-completion/bash_completion`, which is the main script of bash-completion. Depending on your package manager, you have to manually source this file in your `~/.bashrc` file.
|
|
|
|
To find out, reload your shell and run `type _init_completion`. If the command succeeds, you're already set, otherwise add the following to your `~/.bashrc` file:
|
|
|
|
```bash
|
|
source /usr/share/bash-completion/bash_completion
|
|
```
|
|
|
|
Reload your shell and verify that bash-completion is correctly installed by typing `type _init_completion`.
|
|
|
|
### Enable kubectl autocompletion
|
|
|
|
You now need to ensure that the kubectl completion script gets sourced in all your shell sessions. There are two ways in which you can do this:
|
|
|
|
- Source the completion script in your `~/.bashrc` file:
|
|
|
|
```bash
|
|
echo 'source <(kubectl completion bash)' >>~/.bashrc
|
|
```
|
|
|
|
- Add the completion script to the `/etc/bash_completion.d` directory:
|
|
|
|
```bash
|
|
kubectl completion bash >/etc/bash_completion.d/kubectl
|
|
```
|
|
|
|
If you have an alias for kubectl, you can extend shell completion to work with that alias:
|
|
|
|
```bash
|
|
echo 'alias k=kubectl' >>~/.bashrc
|
|
echo 'complete -F __start_kubectl k' >>~/.bashrc
|
|
```
|
|
|
|
{{< note >}}
|
|
bash-completion sources all completion scripts in `/etc/bash_completion.d`.
|
|
{{< /note >}}
|
|
|
|
Both approaches are equivalent. After reloading your shell, kubectl autocompletion should be working.
|