cobra
cobra copied to clipboard
Kubectl bash Autocomplete is broken with latest bash-completion version
What happened: kubectl autocomplete is broken with the below error "bash: _get_comp_words_by_ref: command not found" with 2.14 Bash-completion version. From the bash-completion docs "_get_comp_words_by_ref" seems to be a deprecated API.
What you expected to happen: Bash Autocomplete to work as for older versions.
How to reproduce it (as minimally and precisely as possible): Install latest "bash-completion" package and try out "kubectl" autocomplete.
Anything else we need to know?:
Environment:
Kubernetes client and server versions (use kubectl version):
Client Version: v1.30.5+vmware.3-fips
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.30.5+vmware.3-fips
Cloud provider or hardware configuration:
OS (e.g: cat /etc/os-release): Photon 5
@scop Can you confirm we should not use _get_comp_words_by_ref?
It is deprecated, but using it is still fine. There's no planned timeline when it might be removed (if ever).
https://github.com/scop/bash-completion/blob/e700ae78d7f5c1f4ddd5cdf778ea1a0c6bf1798f/bash_completion.d/000_bash_completion_compat.bash#L12
Switching to the non-deprecated _comp_get_words would mean the completions would only work with bash-completion >= 2.12, which in my opinion would be premature at this point.
Missing _get_comp_words_by_ref sounds like a broken bash-completion setup. The above 000_bash_completion_compat.bash should be installed in a bash_completion.d "compat" dir from where it is automatically and eagerly loaded when the main bash_completion loads.