From 0153f8de1a17668cb8e0a38b02c81d77711a8285 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Mon, 14 Aug 2017 11:24:33 -0700 Subject: [PATCH] Update help/example for kubectl completion --- pkg/kubectl/cmd/completion.go | 53 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/pkg/kubectl/cmd/completion.go b/pkg/kubectl/cmd/completion.go index 10b773c5e93..d14ca66329b 100644 --- a/pkg/kubectl/cmd/completion.go +++ b/pkg/kubectl/cmd/completion.go @@ -50,40 +50,37 @@ var ( completion of kubectl commands. This can be done by sourcing it from the .bash_profile. - Note: this requires the bash-completion framework, which is not installed - by default on Mac. This can be installed by using homebrew: - - $ brew install bash-completion - - Once installed, bash_completion must be evaluated. This can be done by adding the - following line to the .bash_profile - - $ source $(brew --prefix)/etc/bash_completion + Detailed instructions on how to do this are available here: + https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2`)) completion_example = templates.Examples(i18n.T(` - # Install bash completion on a Mac using homebrew - brew install bash-completion - printf " -# Bash completion support -source $(brew --prefix)/etc/bash_completion -" >> $HOME/.bash_profile - source $HOME/.bash_profile + # Installing bash completion on macOS using homebrew + ## If running Bash 3.2 included with macOS + brew install bash-completion + ## or, if running Bash 4.1+ + brew install bash-completion@2 + ## If kubectl is installed via homebrew, this should start working immediately. + ## If you've installed via other means, you may need add the completion to your completion directory + kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl - # Load the kubectl completion code for bash into the current shell - source <(kubectl completion bash) - # Write bash completion code to a file and source if from .bash_profile - kubectl completion bash > ~/.kube/completion.bash.inc - printf " -# Kubectl shell completion -source '$HOME/.kube/completion.bash.inc' -" >> $HOME/.bash_profile - source $HOME/.bash_profile + # Installing bash completion on Linux + ## Load the kubectl completion code for bash into the current shell + source <(kubectl completion bash) + ## Write bash completion code to a file and source if from .bash_profile + kubectl completion bash > ~/.kube/completion.bash.inc + printf " + # Kubectl shell completion + source '$HOME/.kube/completion.bash.inc' + " >> $HOME/.bash_profile + source $HOME/.bash_profile # Load the kubectl completion code for zsh[1] into the current shell - source <(kubectl completion zsh)`)) + source <(kubectl completion zsh) + # Set the kubectl completion code for zsh[1] to autoload on startup + kubectl completion zsh > "${fpath[1]}/_kubectl"`)) ) var ( @@ -141,8 +138,8 @@ func runCompletionBash(out io.Writer, boilerPlate string, kubectl *cobra.Command } func runCompletionZsh(out io.Writer, boilerPlate string, kubectl *cobra.Command) error { - zsh_head := `#compdef kubectl -` + zsh_head := "#compdef kubectl\n" + out.Write([]byte(zsh_head)) if len(boilerPlate) == 0 {