diff --git a/README.md b/README.md index 5216ba5c..4cf65aff 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 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 +``` + + ## 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..00070171 --- /dev/null +++ b/completion/kubie.zsh @@ -0,0 +1,38 @@ +#compdef kubie + +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