hidetatz/kubecolor

Autocomplete does not work.

Closed this issue · 9 comments

Hello @dty1er

I have kubecolor updated after running go get -u github.com/dty1er/kubecolor/cmd/kubecolor. I also have the following in my.zshrc

# kubecolor
alias kubectl=kubecolor
complete -o default -F __start_kubectl kubectl

So, when I typed kubectl command, my autocomplete did not work. Then, I removed the above kubecolor config in my .zshrc, and ran source ~/.zshrc to get the latest changes on my src file.

I re-tried kubectl again, and the autocomplete still did not work.

After I removed that kubecolor config, I checked the following:

▶ which kubectl
kubectl: aliased to kubecolor
▶ which kubecolor
/Users/lpurba/go/bin/kubecolor

Why the autocomplete did not work? Also, after removing kubecolor config and sourceing the src file, why my kubectl was still an alias of kubecolor?

Having autocomplete is very helpful. I appreciate your help

Thank you,
Laurentius

@laurentiuspurba
Hi, thank you for opening an issue.
Let me take a look and will get back to you later.

@laurentiuspurba
Can you share your output of kubectl versions --short and zsh --version ?

@dty1er Here is the info as requested

▶ kubectl version --short
Client Version: v1.19.2
Server Version: v1.15.12-gke.20
▶ zsh --version
zsh 5.3 (x86_64-apple-darwin18.0)

Appreciate your response.

@laurentiuspurba
Hi, I identified the root cause of the issue and trying to fix it. Please wait for a while.

@laurentiuspurba
Hi, I applied some fix in kubecolor so can you update kubecolor by go get -u.
Also, about autocomplete, please make sure below things:

  • First, you need source <(kubectl completion zsh) in your .zshrc . Is it already written?
  • when you set the alias alias kubectl=kubecolor, you don't need complete -o default -F __start_kubectl kubectl .

So now, I want you to do below:

  • go get -u github.com/dty1er/kubecolor/cmd/kubecolor
  • make sure source <(kubectl completion zsh) exists in your .zshrc
  • make sure complete -o default -F __start_kubectl kubectl is NOT in your .zshrc
  • make sure alias kubectl=kubecolor exists in your .zshrc
  • source ~/.zshrc

If it still does not work, please let me know!

@dty1er
After doing what you suggested, the autocomplete still does not work. This is what I have in my .zshrc

# kubecolor
source <(kubectl completion zsh)
alias kubectl=kubecolor

and then I did source ~/.zshrc, and the result was still the same.

Is there a way to revert it back to previous setting without kubecolor? I removed anything related to kubecolor in my .zshrc, but it still uses kubecolor for some reasons.

Thanks

@laurentiuspurba

Hi, thank you for trying.
I setup zsh environment and found the solution I suggested doesn't work (sorry but I assumed it should work because it's working on my bash env).

  • Reverting the configuration

To revert it, I found you need to run unalias it explicitly because configured alias is still remaining after you removed it in your zshrc. Can you run unalias kubectl ?

  • How to get completion works

In addition to what I suggested already, you need compdef kubecolor=kubectl .
so can you try with below zshrc:

# get zsh complete kubectl
source <(kubectl completion zsh)
alias kubectl=kubecolor
# make completion work with kubecolor
compdef kubecolor=kubectl

@laurentiuspurba
I close this issue for now, but please don't mind opening it again if you want!

I get this error in bash with kubernetes 1.25 ubuntu 22.04LTS

alias k=kubecolor
source<(kubectl completion bash)
complete -o default -F __start_kubectl k

k

k -bash: 4: syntax error: invalid arithmetic operator (error token is "")