From b65758a67b67acc919a726154a424889ef55e42a Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 18 Oct 2023 20:35:18 +0200 Subject: [PATCH 1/4] Added basic autocompletion for zsh. (#34) --- README.md | 15 +++++++++++++++ completion/kubie.zsh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 completion/kubie.zsh diff --git a/README.md b/README.md index 5216ba5c..42779578 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,21 @@ cp completion/kubie.fish ~/.config/fish/completions/ Then reopen fish or source the file. + +#### Zsh + +Autocomplete with Zsh can either be installed by sourcing the file eg.: + +```bash +source ./completion/kubie.zsh +``` + +Or by adding it to your fpath and renaming the completion file to _kubie eg.: +```bash +cp .completion/kubie.zsh ~/.zsh/completions +``` + + ## Usage Selectable menus will be available when using `kubie ctx` and `kubie ns`. diff --git a/completion/kubie.zsh b/completion/kubie.zsh new file mode 100644 index 00000000..5ae52223 --- /dev/null +++ b/completion/kubie.zsh @@ -0,0 +1,36 @@ +function _kubie { + local -a subcmds + local context state line + + _arguments -C \ + '1: :->param1' \ + '2: :->param2' \ + '3: :->param3' && return 0 + + case $state in + param1) + subcmds=('ctx' 'edit' 'edit-config' 'exec' 'help' 'info' 'lint' 'ns') + _describe 'command' subcmds + ;; + param2) + case $line[1] in + ctx|edit|exec) + subcmds=(${(f)"$(kubie ctx)"}) + _describe 'context' subcmds + ;; + ns) + subcmds=(${(f)"$(kubie ns)"}) + _describe 'namespace' subcmds + ;; + esac + ;; + param3) + if [[ $line[1] == 'exec' ]]; then + subcmds=(${(f)"$(kubie exec $line[2] default kubectl get namespaces | tail -n+2 | awk '{print $1}')"}) + _describe 'namespace' subcmds + fi + ;; + esac +} + +compdef _kubie kubie From b29eadb8b5b677fe9338792abf50b11981050e19 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 7 Jan 2024 21:00:23 +0100 Subject: [PATCH 2/4] Adding compdef to start of autocompletion script. Thanks juanmirocks Co-authored-by: Dr. Juan Miguel Cejuela --- completion/kubie.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/completion/kubie.zsh b/completion/kubie.zsh index 5ae52223..00070171 100644 --- a/completion/kubie.zsh +++ b/completion/kubie.zsh @@ -1,3 +1,5 @@ +#compdef kubie + function _kubie { local -a subcmds local context state line From c849ad11b7578c9dede32444299328554154ffb7 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 10 Jun 2024 22:33:22 +0200 Subject: [PATCH 3/4] Correcting name of zsh completion file Co-authored-by: Dr. Juan Miguel Cejuela --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42779578..40ca933d 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ source ./completion/kubie.zsh Or by adding it to your fpath and renaming the completion file to _kubie eg.: ```bash -cp .completion/kubie.zsh ~/.zsh/completions +cp ./completion/kubie.zsh ~/.zsh/_kubie ``` From 6180ca4ef37d9cc836bfd7f392f5a5d7c966f467 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 10 Jun 2024 22:33:46 +0200 Subject: [PATCH 4/4] Adding more documentation for setup with fpath Co-authored-by: Dr. Juan Miguel Cejuela --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40ca933d..4cf65aff 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Autocomplete with Zsh can either be installed by sourcing the file eg.: source ./completion/kubie.zsh ``` -Or by adding it to your fpath and renaming the completion file to _kubie eg.: +Or by adding the file to one of your [`fpath`](https://zsh.sourceforge.io/Doc/Release/Functions.html#Autoloading-Functions) folders, for instance `~/.zsh`, and making sure [zsh autocompletion is initialized](https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Initialization) ([for instance](https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh)): ```bash cp ./completion/kubie.zsh ~/.zsh/_kubie ```