From 17b32b1f64060f21df9e6d6645051b75785c3e2d Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Tue, 4 Apr 2017 12:05:28 -0700 Subject: [PATCH] Add basic bash completion Signed-off-by: Ahmet Alp Balkan --- README.md | 8 ++++---- completion/README.md | 19 +++++++++++++++++++ completion/kubectx.bash | 8 ++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 completion/README.md create mode 100644 completion/kubectx.bash diff --git a/README.md b/README.md index c69913e..2bd2cab 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ Context "dublin" set. Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin". ``` -## Help wanted +[**Set up `bash` completion →**](completion/README.md) -- [ ] bash completion -- [ ] zsh completion -- [ ] homebrew formula/tap +### Help wanted + +[ ] homebrew formula/tap ----- diff --git a/completion/README.md b/completion/README.md new file mode 100644 index 0000000..c93dd9a --- /dev/null +++ b/completion/README.md @@ -0,0 +1,19 @@ +kubectx provides shell completion scripts to complete context names, making it +even faster to switch between contexts easily. + +## Bash setup + +Copy the `kubectx.bash` file to your HOME directory: + + cp kubectx.bash ~/.kubectx.bash + +And source it in your `~/.bashrc` file by adding the line: + + [ -f ~/.kubectx.bash ] && source ~/.kubectx.bash + +Start a new shell, type `kubectx`, then hit Tab to see the existing +contexts. + +You can Add `TAB: menu-complete` to your `~/.inputrc` to cycle through the +options with Tab. + diff --git a/completion/kubectx.bash b/completion/kubectx.bash new file mode 100644 index 0000000..c51d9c3 --- /dev/null +++ b/completion/kubectx.bash @@ -0,0 +1,8 @@ +_kube_contexts() +{ + local curr_arg; + curr_arg=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "- $(kubectl config get-contexts | awk '{print $2}' | tail -n +2)" -- $curr_arg ) ); +} + +complete -F _kube_contexts kubectx \ No newline at end of file