From 81cd522d7d89ac898f5fe9f0c814afe054d50bf9 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Tue, 4 Apr 2017 12:26:47 -0700 Subject: [PATCH] Use bash completion for zsh completion Signed-off-by: Ahmet Alp Balkan --- README.md | 6 +++--- completion/README.md | 30 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2bd2cab..f142bfe 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ about how `kubectl` can manage contexts better. ## Example -``` +```sh $ kubectx minikube Switched to context "minikube". @@ -31,11 +31,11 @@ Context "dublin" set. Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin". ``` -[**Set up `bash` completion →**](completion/README.md) +[Set up `bash` and `zsh` completion →](completion/README.md) ### Help wanted -[ ] homebrew formula/tap +[ ] homebrew formula/tap that installs the script and completions ----- diff --git a/completion/README.md b/completion/README.md index c93dd9a..fe4bba9 100644 --- a/completion/README.md +++ b/completion/README.md @@ -5,11 +5,15 @@ even faster to switch between contexts easily. Copy the `kubectx.bash` file to your HOME directory: - cp kubectx.bash ~/.kubectx.bash +```sh +cp kubectx.bash ~/.kubectx.bash +``` And source it in your `~/.bashrc` file by adding the line: - [ -f ~/.kubectx.bash ] && source ~/.kubectx.bash +```sh +[ -f ~/.kubectx.bash ] && source ~/.kubectx.bash +``` Start a new shell, type `kubectx`, then hit Tab to see the existing contexts. @@ -17,3 +21,25 @@ contexts. You can Add `TAB: menu-complete` to your `~/.inputrc` to cycle through the options with Tab. +## Zsh setup + +`zsh` can leverage the `bash` completion scripts. Copy the `kubectx.bash` file +to your HOME directory: + +```sh +cp kubectx.bash ~/.kubectx.bash +``` + +And add the following to your `.zshrc`: + +```sh +[ -f ~/.kubectx.bash ] && source ~/.kubectx.bash +``` + +Start a new shell, type `kubectx`, then hit Tab to see the existing +contexts. If it does not work, modify the line above to: + +```sh +[ -f ~/.kubectx.bash ] && autoload bashcompinit && bashcompinit && \ + source ~/.kubectx.bash +```