Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic autocompletion for zsh. (#34) #175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
Comment on lines +70 to +74

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this will work for the current session ONLY. So it's not the solution or otherwise it should be properly noted.


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
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can add extra notes for oh-my-zsh

cp .completion/kubie.zsh ${ZSH}/custom/completions/_kubie.zsh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done some steps but it's not working for me.

kubie ns autocomplete is not working for me

Copy link

@mhkarimi1383 mhkarimi1383 Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autocomplete for kubie itself is also not working


## Usage
Selectable menus will be available when using `kubie ctx` and `kubie ns`.

Expand Down
38 changes: 38 additions & 0 deletions completion/kubie.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#compdef kubie

function _kubie {
antring marked this conversation as resolved.
Show resolved Hide resolved
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