-
Notifications
You must be signed in to change notification settings - Fork 102
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have done some steps but it's not working for me.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. autocomplete for |
||
|
||
## Usage | ||
Selectable menus will be available when using `kubie ctx` and `kubie ns`. | ||
|
||
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be added to the zsh profile (e.g. ~/.zshrc).
Then it will be valid for all sessions.