vmware-archive / ktx

manage kubernetes cluster configs
Apache License 2.0
135 stars 24 forks source link

Completion doesn't work on zsh #22

Open mylesagray opened 5 years ago

mylesagray commented 5 years ago

Env: macOS 10.14 / zsh + oh-my-zsh shell

ktx completion doesn't work because zsh doesn't have the complete keyword like bash does.

Is there any way you can add completion that supports zsh too?

chuckha commented 5 years ago

cc @xstevens ?

I don't have any zsh experience and rely on others for this support

EDIT: that said, i can look into this at some point

chuckha commented 5 years ago

cc @mdaverde

.... :D

mylesagray commented 5 years ago

As for examples:

https://github.com/ahmetb/kubectx/blob/master/completion/kubectx.bash https://github.com/ahmetb/kubectx/blob/master/completion/kubectx.zsh

scottslowe commented 3 years ago

@mylesagray Hey Myles, I was just setting up my new M1-based Mac and getting ktx working under Zsh 5.8. I was able to make completion work this way.

I created a completion function (named _ktx) and placed it into ~/.zsh/functions (which is part of the FPATH). The contents of this file:

#compdef ktx

KUBECONFIG_DIR=${KUBECONFIG_DIR:-"${HOME}/.kube/"}

_ktx() {
       _arguments -s -S \
              "*::filename:_files -W ${KUBECONFIG_DIR}"
}

I already had initialized the completion system in ~/.zshrc with autoload -Uz compinit && compinit. I still need to do some fine-tuning, but it does work.

Hope this helps!

mylesagray commented 3 years ago

That did the trick, thanks @scottslowe! - hope the new gig is working out for you too :)