kubectx icon indicating copy to clipboard operation
kubectx copied to clipboard

Autocomplete breaks when multiple longer contexts match

Open marevers opened this issue 2 years ago • 2 comments

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.

marevers avatar Dec 21 '23 13:12 marevers

  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.

ahmetb avatar Jan 06 '24 00:01 ahmetb

  1. bash
  2. Go implementation (version 0.9.5)

marevers avatar Jan 08 '24 09:01 marevers