Closed bygui86 closed 3 years ago
Have a look here, works for my zsh setup: https://github.com/dty1er/kubecolor/issues/32#issuecomment-724411738
Thanks @ecsecta ! I will try asap
@ecsecta unfortunately the solution you proposed does not work.
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
with complete -o default -F __start_kubectl kubectl
commented
I forgot to mention:
brew
@bygui86 Can you show me the whole .zshrc? On my environment this works:
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
@dty1er I could but it would be pretty difficult to read... as I work on many different technologies everyday and I use tons of tools, I organised .zshrc in multiple subfiles to keep everything tidy.
Here an example of the .zshrc structure:
source configs.sh
source oh-my-zsh.zsh
source env-vars.sh
source ps1-prompt.sh
source functions.sh
source path.sh
source aliases.sh
source company_configs.sh
source autocompletion.sh
I tried both following ways (commenting everything else related to kubectl and k):
# ...
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
# ...
### load all aliases together
# some aliases (e.g. ll, ...)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
# some other aliases (e.g. gcloud, kubectx, kubens, ...)
### source all autocompletion together
# source some autocompletion (e.g. brew, ...)
source <(kubectl completion zsh)
# source some other autocompletion (e.g. gcloud, helm, ...)
but still it doesn't work.
I will try excluding everything and loading only your 3 lines, let's see...
I tried with a super minimal .zshrc:
#!/bin/zsh
source "$HOME/oh-my-zsh.zsh"
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
and it worked!
Now I have to guess which of my other scripts creates this issue :(
@dty1er any known conflict between kubecolor and other tools? for example gcloud, krew, kubectx, kubens or similar?
@bygui86 I see. Unfortunately, I currently don't know any tools which make the completion not working. I guess you can investigate it by bisecting your .zshrc. If you can find which part was causing this problem, I'd like you to report it here. The information should be much helpful for other people, so I want to consider writing it in this project README.
@dty1er I found the conflict:
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
I use these lines to load zsh-completions
.
Everything depends on the order...
WORKS
#!/bin/zsh
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
source "$HOME/oh-my-zsh.zsh"
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
DOES NOT WORK
#!/bin/zsh
source "$HOME/oh-my-zsh.zsh"
source <(kubectl completion zsh)
alias kubectl="kubecolor"
compdef kubecolor="kubectl"
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
No matter other aliases, functions or autocompletions loaded before or after...
@bygui86
Thank you for your effort! I don't understand how zsh completion works deeply, but it seems like compinit should be located before compdef? I could find something similar, but I'm still not sure.
Anyway, I'm happy to hear it worked on your environment. Let me close this issue for now, but please feel free to reopen or open another one when you found something else. Thank you for using kubecolor!
I am having a similar problem with the oh-my-zsh plugin, has anyone figured out how to make them work, without explicitly sourcing the autocomplete?
.zshrc
file:
command -v kubecolor >/dev/null 2>&1 && alias kubectl="kubecolor" && compdef kubecolor="kubectl"
Currently, I cannot use the autocomplete or badges the plugin provides.
I tried to enable the autocompletion for kubecolor following instructions on the official README:
but it does not work, no autocompletion for kubecolor and even worse no autocompletion anymore for
k
alias!Here some info:
k
alias set and autocompletion properly working (without enabling kubecolor autocompletion)Here the output of
kubectl version
command:Any help is really appreciated!!