Update help/example for kubectl completion

This commit is contained in:
Christoph Blecker 2017-08-14 11:24:33 -07:00
parent 70b942d663
commit 0153f8de1a
No known key found for this signature in database
GPG Key ID: B34A59A9D39F838B

View File

@ -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 {