ahmetb / kubectx

Faster way to switch between clusters and namespaces in kubectl
https://kubectx.dev
Apache License 2.0
17.8k stars 1.27k forks source link

Autocomplete breaks when multiple longer contexts match #411

Open marevers opened 10 months ago

marevers commented 10 months ago

I have multiple contexts from AWS clusters, which by default have the entire cluster ARN as their context name (e.g. arn:aws:eks:us-east-2:112233445566:cluster/my-cluster-in-aws).

If I try to autocomplete with only one matching context, then everything works fine, however, if there are multiple matching contexts (e.g. hitting TAB after typing arn:aws), it will autocomplete until the first diverging character and no list of options will come up on a second press. Typing any further characters that match one of the options does not allow autocompleting the context name either.

Example:

Let us assume there is two contexts and we try to autocomplete.


$ kubectx
arn:aws:eks:us-east-2:112233445566:cluster/my-cluster-in-aws
arn:aws:eks:us-west-2:112233445566:cluster/my-cluster-in-aws-two

$ kubectx arn

Now I hit TAB to autocomplete.

$ kubectx arn:aws:eks:us-

Another TAB hit does nothing at this point. The two options are not shown. I type an 'e' to only match the first context.

$ kubectx arn:aws:eks:us-e

Pressing TAB now does nothing anymore, the first context is not autocompleted.

I am aware I can rename the contexts. If I rename to use shorter names, then everything works fine. I have also tested the presence of the slash in the context name. Removing that has no effect. If there is only a single match of such a length, the autocomplete works without issues.

ahmetb commented 10 months ago

1) are you using bash or zsh 2) are you using the Go implementation or the bash script implementation of kubectx? (vi $(which kubectx) can help find).

I'm not observing this behavior with the bash script implementation+zsh with the context names you pasted.

marevers commented 10 months ago
  1. bash
  2. Go implementation (version 0.9.5)