diff --git a/README.md b/README.md index e0ad15ec..a0edb483 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,8 @@ Getting cluster info and generating kubekey's configuration file (optional). * [Addons](docs/addons.md) * [Network access](docs/network-access.md) * [Storage clients](docs/storage-client.md) -* [Kubectl autocompletion](docs/kubectl-autocompletion.md) +* [kubectl auto-completion](docs/kubectl-autocompletion.md) +* [kubekey auto-completion](docs/kubekey-autocompletion.md) * [Roadmap](docs/roadmap.md) * [Check-Renew-Certificate](docs/check-renew-certificate.md) * [Developer-Guide](docs/developer-guide.md) diff --git a/cmd/completion.go b/cmd/completion.go index 512a0e46..b1cc37e1 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -54,17 +54,18 @@ var completionCmd = &cobra.Command{ Short: "Generate shell completion scripts", Long: `Generate shell completion scripts Normally you don't need to do more extra work to have this feature if you've installed kk by brew`, - Example: `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 -You may need to add the completion to your completion directory by the following command -kk completion > $(brew --prefix)/etc/bash_completion.d/kk -If you get trouble, please visit https://github.com/jenkins-zh/jenkins-cli/issues/83. - -Load kk completion code for bash into the current shell -source <(kk completion --type bash) + Example: `# Installing bash completion on Linux +## If bash-completion is not installed on Linux, please install the 'bash-completion' package +## via your distribution's package manager. +## Load the ks completion code for bash into the current shell +source <(ks completion bash) +## Write bash completion code to a file and source if from .bash_profile +mkdir -p ~/.config/kk/ && kk completion --type bash > ~/.config/kk/completion.bash.inc +printf " +# kk shell completion +source '$HOME/.config/kk/completion.bash.inc' +" >> $HOME/.bash_profile +source $HOME/.bash_profile In order to have good experience on zsh completion, ohmyzsh is a good choice. Please install ohmyzsh by the following command diff --git a/docs/kubekey-autocompletion.md b/docs/kubekey-autocompletion.md new file mode 100644 index 00000000..1d952a2e --- /dev/null +++ b/docs/kubekey-autocompletion.md @@ -0,0 +1,25 @@ +Enable kubekey auto-completion +------------ + +**Prerequisite**: make sure `bash-completion` is installed and does workk. + +## Bash Completion + +You can install it via your distribution's package manager. + +For Ubuntu, `apt-get install bash-completion` + +For CentOS, `yum install -y bash-completion` + +## Setup Completion + +Write bash completion code to a file and source if from .bash_profile. + +``` +mkdir -p ~/.config/kk/ && kk completion bash > ~/.config/kk/completion.bash.inc +printf " +# kk shell completion +source '$HOME/.config/kk/completion.bash.inc' +" >> $HOME/.bash_profile +source $HOME/.bash_profile +```