Skip to content

Commit

Permalink
Added basic autocompletion for zsh. (sbstp#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
antring committed Oct 18, 2023
1 parent 80e6178 commit b65758a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
36 changes: 36 additions & 0 deletions completion/kubie.zsh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b65758a

Please sign in to comment.