kubectl: Cannot autocomplete kubectl bash aliases
The default kubectl
complete function __start_kubectl
does not work with bash aliases:
# ~/.aliases
alias k="kubectl"
complete -o default -F __start_kubectl k
Actual output:
~$ k [TAB]
k kubectl
~$ k k [TAB]
k kubectl
Expected output:
~$ k [TAB]
annotate convert expose rolling-update
api-versions cordon get rollout
apply cp label run
attach create logs scale
auth delete options set
autoscale describe patch taint
certificate drain plugin top
cluster-info edit port-forward uncordon
completion exec proxy version
config explain replace
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 36
- Comments: 40 (5 by maintainers)
Commits related to this issue
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to kubernetes/kubernetes by deleted user 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to kubernetes/kube-aggregator by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to kubernetes/sample-apiserver by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to kubernetes/apiextensions-apiserver by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to sttts/kube-aggregator by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to sttts/sample-apiserver by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to sttts/apiextensions-apiserver by k8s-publishing-bot 6 years ago
- Merge pull request #60689 from nikhita/bump-cobra-bash-alias Automatic merge from submit-queue (batch tested with PRs 60732, 60689, 60648, 60704). If you want to cherry-pick this change to another br... — committed to openshift/kubernetes-sample-apiserver by k8s-publishing-bot 6 years ago
- Merge pull request #120 from sttts/sttts-rebase-carries-1.18 Re-add missing UPSTREAM commits from rebase branch Kubernetes-commit: 754da5451727326671fbee043b64452ab0570572 — committed to openshift/kubernetes-kubectl by k8s-publishing-bot 4 years ago
I don’t know if this is the best/right solution, but I made
k
autocomplete by doingsource <(kubectl completion bash | sed 's/kubectl/k/g')
.https://github.com/cykerway/complete-alias is kind of amazing. With this, there is no need to modify the original completion functions, and it works with lazily-loaded completions.
The official instructions are not working for me with
bash
4.3 and 4.4. After adding the commands below, completing withkubectl
works fine, butk
doesn’t. If I type ‘k’, ‘space’ and then press tab is expands to ‘k kubectl’ and then if I press tab again it starts completingkubectl
commands. Do the official approach only work withbash
5.x?This does not work,
k
completes tok kubectl
:Using
complete_alias
does work:And this workaround of duplicating the completions does also work:
I followed official guide and the issue is gone.
https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
What I was missing is
/unsubscribe
/assign
I added this into ~/.bash_profile
@weibeld Yes. Where _complete_alias is __start_kubectl
Can someone help to update the vendor to pick up the fix in cobra?