kubectl zsh completion cause directory path completion has extra space

Created on 6 Apr 2018  Â·  18Comments  Â·  Source: kubernetes/kubectl

Is this a BUG REPORT or FEATURE REQUEST? : BUG REPORT

Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration: Aliyun ECS
  • OS: Ubuntu 16.04.4 LTS
  • Kernel: 4.4.0-105-generic
  • Install tools: zsh 5.1.1

What happened:

When hit tab to complete a sub directory path, zsh added an extra space after the directory path.
It causes press tab repeatly to complete additional path impossible.

What you expected to happen:

Like bash completion, only file completion with extra space, there should be no space after directory.

How to reproduce it:

  1. Says there is a file foo/bar.yaml;
  2. Typing kubectl apply -f f, then press tab;
  3. It complete with foo/<space>, instead of foo/;
  4. I need to delete this extra space, then press tab again to complete the file bar.yaml。

But there is another situation working correctly.

  1. Same as ~/foo/bar.yaml;
  2. Typing kubectl apply -f ~/f, then press tab, it finished with kubectl apply -f ~/foo/.

Anything else we need to know:

From debug log, I got this for f completion.

_filedir @(json|yaml|yml) cur=f
RET=foo len=1

Got this for ~/f completion.

_filedir @(json|yaml|yml) cur=~/f
RET= len=0

It seems there is something different in RET=( $(compgen -f) ) of completion.go.

arekubectl kinbug prioritP2 sicli

Most helpful comment

A workaround for me is to just remove kubectl's completion for the "-f" flag and let it fallback to the standard zsh file / path completion.

I used

source <(kubectl completion zsh | sed '/"-f"/d')

instead of

source <(kubectl completion zsh)

All 18 comments

Any update on this?

/sig cli
/area kubectl
/kind bug
/priority P2

Can also reproduce on the below environment. ~Similar to the working situation above with the tilde, autocompletion ofkubectl apply -f ./f does not cause this issue.~ (strike this, it seems broken with . relative filenames too).

Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.2", GitCommit:"17c77c7898218073f14c8d573582e8d2313dc740", GitTreeState:"clean", BuildDate:"2018-10-30T21:39:38Z", GoVersion:"go1.11.1", Compiler:"gc", Platform:"darwin/amd64"}

Environment:
OS: macOS Mojave 10.14.1
Kernel: Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64
Install tools: zsh 5.6.2

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

A workaround for me is to just remove kubectl's completion for the "-f" flag and let it fallback to the standard zsh file / path completion.

I used

source <(kubectl completion zsh | sed '/"-f"/d')

instead of

source <(kubectl completion zsh)

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Same issue here

Same issue here

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Same issue here.

kubectl version info

Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:41:24Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}

zsh version info

zsh 5.8 (x86_64-apple-darwin19.3.0)

I have filed a PR https://github.com/kubernetes/kubernetes/pull/89479 to fix this issue, please give it a try and feel free to tell me any problem you encountered.

/assign knight42

A workaround for me is to just remove kubectl's completion for the "-f" flag and let it fallback to the standard zsh file / path completion.

I used

source <(kubectl completion zsh | sed '/"-f"/d')

instead of

source <(kubectl completion zsh)

I had to do the following, I just replaced with foo cause I was a bit frustrated

in this file

 ~/.o/p/k/kubectl.plugin.zsh                                                                                                                                                  
 if (( $+commands[kubectl] )); then
     __KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"

     if [[ ! -f $__KUBECTL_COMPLETION_FILE || ! -s $__KUBECTL_COMPLETION_FILE ]]; then
         kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
     fi
vim ~/.oh-my-zsh/plugins/kubectl/kubectl.plugin.zsh

Change

kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE

->

(kubectl completion zsh | sed "s/kubectl_apply/foo/g") >! $__KUBECTL_COMPLETION_FILE

then

rm ~/.oh-my-zsh/cache/kubectl_completion

then start new shell

Was this page helpful?
0 / 5 - 0 ratings