kubernetes: kubectl bash completion causes bash file path completion to fail
Is this a BUG REPORT or FEATURE REQUEST?:
/kind bug
What happened:
Bash file path completion fails when trying to run kubectl
commands and source /usr/local/etc/bash_completion.d/kubectl
is in ~/.bash_profile
. If I run kubectl delete -f ../<TAB>
then I get the error message show below in the section on reproduction.
What you expected to happen:
I espect to see files/directories that ../
can complete to.
How to reproduce it (as minimally and precisely as possible):
Amits-MacBook-Pro:boku amitgupta$ cat ~/.bash_profile
### kubectl ###
source /usr/local/etc/bash_completion.d/kubectl
Amits-MacBook-Pro:boku amitgupta$ exec -l $SHELL
Amits-MacBook-Pro:boku amitgupta$ kubectl ../bash: __ltrim_colon_completions: command not found
I hit <TAB>
after kubectl ../
.
Anything else we need to know?:
This problem arises only with the kubectl
command, not any others.
It arises no matter what I seem to put in after kubectl
, even kubectl <SPACE><TAB>
brings up the issue, doesn’t have to be something like kubectl delete -f ../<TAB>
.
The error message changes. In the example above, it says bash: __ltrim_colon_completions: command not found
, but sometimes it says bash: _filedir: command not found
in the same place.
When I remove kubectl
Bash completions from my ~/.bash_profile
(and restart/re-login to the shell), the problem goes away. These file completions came with my Homebrew installation of kubectl
.
There is no difference between what Homebrew provided and what kubectl completion bash
provides:
$ diff <(kubectl completion bash) /usr/local/etc/bash_completion.d/kubectl
Environment:
- Kubernetes version (use
kubectl version
):$ kubectl version Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.0", GitCommit:"d3ada0119e776222f11ec7945e6d860061339aad", GitTreeState:"clean", BuildDate:"2017-06-30T09:51:01Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"darwin/amd64"} Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.6", GitCommit:"7fa1c1756d8bc963f1a389f4a6937dc71f08ada2", GitTreeState:"clean", BuildDate:"2017-06-16T18:21:54Z", GoVersion:"go1.7.6", Compiler:"gc", Platform:"linux/amd64"}
- Cloud provider or hardware configuration**: N/A
- OS (e.g. from /etc/os-release):
$ sw_vers ProductName: Mac OS X ProductVersion: 10.12.5 BuildVersion: 16F2104
- Kernel (e.g.
uname -a
):$ uname -a Darwin Amits-MacBook-Pro.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:13:31 PDT 2017; root:xnu-3789.60.24~4/RELEASE_X86_64 x86_64
- Install tools:
$ brew --version Homebrew 1.2.4 Homebrew/homebrew-core (git revision 36f1; last commit 2017-07-06) $ brew info --json=v1 kubectl | jq '.[0].name,.[0].installed[0].version' -r kubernetes-cli 1.7.0
- Others:
$ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16) Copyright (C) 2007 Free Software Foundation, Inc.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 18 (5 by maintainers)
Commits related to this issue
- Support bash-completion on brew (for kubectl) see https://github.com/kubernetes/kubernetes/issues/48575#issuecomment-338638089 — committed to jhunt/env by jhunt 4 years ago
- fix kubectl autocomplete not completing files https://github.com/kubernetes/kubernetes/issues/48575 — committed to grosser/dotfiles by grosser 2 years ago
I’m on Windows with MinGW. After digging into system directories, it seems
bash_completion
script which contains helper functions such as_filedir
is missing.I had to get files from Git repository at https://github.com/scop/bash-completion/blob/master/bash_completion to
/usr/share/bash-completion/bash_completion
Then add following line on top of my
~/.bashrc
:You need to source bash-completion from either
/etc/bashrc
or~/.bashrc
. Seekubectl completion -h
for more details.I had same problem on OSX with native bash:
It seems like, the whole thing only works when:
brew install bash-completion@2
kubectl completion bash > ~/.kube/kubectl_autocompletion
, then source it in~/.bash_profile
above code snippet is what the final addition to my ~/.bash_profile
I had the same in Manjaro ( archlinux ), in addition to @simonxy :
pacman -S bash-completion kubectl completion bash > ~/.kube/kubectl_autocompletion
add to .bashrcif [ -f /usr/local/share/bash-completion/bash_completion ]; then . /usr/local/share/bash-completion/bash_completion fi source ~/.kube/kubectl_autocompletion
and runsource .bashrc
Btw, on macOS if you have upgraded your bash to 4+, make sure to change your shell via
chsh
. More info here: https://apple.stackexchange.com/a/55998/273340Think I figured it out, I missed the part in the Examples section of the
kubectl completion -h
output which says tobrew install bash-completion
. The completion kind of works even without this, e.g.kubectl ap<TAB>
gives: