From 689c4b02b48783991c2e8cdf2e6c2a7446b8546d Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Fri, 21 Oct 2016 21:05:38 -0400 Subject: [PATCH] Add kubectl shell autocompletion section --- docs/getting-started-guides/kubectl.md | 43 +++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/getting-started-guides/kubectl.md b/docs/getting-started-guides/kubectl.md index 0498ceb646..b346b75c7d 100644 --- a/docs/getting-started-guides/kubectl.md +++ b/docs/getting-started-guides/kubectl.md @@ -63,4 +63,45 @@ brew install kubectl ``` The homebrew project is independent from kubernetes, so do check that the version is -sufficiently up-to-date using `kubectl version`. \ No newline at end of file +sufficiently up-to-date using `kubectl version`. + + +# Enabling shell autocompletion + +kubectl includes autocompletion support, which can save a lot of typing! + +The completion script itself is generated by kubectl, so you typically just need to invoke it from your profile. + +Common examples are provided here, but for more details please consult `kubectl completion -h` + +## On Linux, using bash + +To add it to your current shell: `source <(kubectl completion bash)` + +To add kubectl autocompletion to your profile (so it is automatically loaded in future shells): + +```shell +echo "source <(kubectl completion bash)" >> ~/.bashrc +``` + +## On MacOS, using bash + +On MacOS, you will need to install the bash-completion support first: + +```shell +brew install bash-completion +``` + +To add it to your current shell: + +```shell +source $(brew --prefix)/etc/bash_completion +source <(kubectl completion bash) +``` + +To add kubectl autocompletion to your profile (so it is automatically loaded in future shells): + +```shell +echo "source $(brew --prefix)/etc/bash_completion" >> ~/.bashrc +echo "source <(kubectl completion bash)" >> ~/.bashrc +```