Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Krew completion (for fish, likely others as well) only works if ln -s kubectl-krew krew, and even then not in kubectl krew #810

Closed
vorburger opened this issue Oct 23, 2022 · 9 comments

Comments

@vorburger
Copy link

#769 similar issue

When installing krew as per https://krew.sigs.k8s.io/docs/user-guide/setup/install/, for Fish (but it's likely similar for other shells),

and then activating completion like this:

$HOME/.krew/bin/kubectl-krew completion fish > $HOME/.config/fish/completions/kubectl-krew.fish

then kubectl krew ... still doesn't auto-complete. However if doing:

ln -s $HOME/.krew/bin/kubectl-krew $HOME/.krew/bin/krew

then at least krew ... auto-completes.

@vorburger
Copy link
Author

and then activating completion like this:

as suggested to be added to the doc in #811, as at least a first step

@ahmetb
Copy link
Member

ahmetb commented Oct 24, 2022

Krew doesn't offer completion, because kubectl plugins don't support completion yet.

If it appears like krew does have completion scripts, it's a side effect of the library we use, not by design.

/close

@k8s-ci-robot
Copy link
Contributor

@ahmetb: Closing this issue.

In response to this:

Krew doesn't offer completion, because kubectl plugins don't support completion yet.

If it appears like krew does have completion scripts, it's a side effect of the library we use, not by design.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@chriskim06
Copy link
Member

also the next time we publish a new version the completion command won't be there #771

@maelvls
Copy link

maelvls commented Feb 3, 2023

With the latest kubectl version (1.26), the kubectl plugins completion now works!

To enable completion for kubectl krew, run the following commands:

echo '#!/bin/sh\nkubectl krew __complete "$@"' >~/.krew/bin/kubectl_complete-krew
chmod u+x ~/.krew/bin/kubectl_complete-krew

@ahmetb
Copy link
Member

ahmetb commented Feb 3, 2023

@maelvls we should probably implement a native feature for this in the plugin manifest. Do you mind opening a separate issue so I don't forget?

@maelvls
Copy link

maelvls commented Feb 4, 2023

I think #812 covers this 👍

@chisaato
Copy link

For anyone using zi or zinit, this is a workaround.

from"{{ choose_github_mirror() }}" is a ansible template, you can remove it if there is nothing blocking access to github.

# kubecm 多集群配置管理工具
zi lucid wait'1' has"kubectl-kc" for \
    id-as"kubecm_completion" \
    from"{{ choose_github_mirror() }}" \
    as"completion" \
    atclone"kubectl-kc completion zsh > _kubecm; zinit creinstall -q kubecm_completion" \
    atinit"ln -sf $HOME/.krew/bin/kubectl-kc $ZPFX/bin/kubecm;
    compdef _kubecm kubectl-kc;
    echo '#!/bin/sh\nkubectl kc __complete \"\$@\"' > $HOME/.krew/bin/kubectl_complete-kc;
    chmod +x $HOME/.krew/bin/kubectl_complete-kc" \
    atpull"%atclone" \
    run-atpull \
    z-shell/null

# Krew kubectl 插件管理器
zi lucid wait'1' has"kubectl-krew" for \
    id-as"krew_completion" \
    from"{{ choose_github_mirror() }}" \
    as"completion" \
    atclone"kubectl-krew completion zsh > _krew; zinit creinstall -q krew_completion" \
    atinit"ln -sf $HOME/.krew/bin/kubectl-krew $ZPFX/bin/krew;compdef _krew kubectl-krew;
    echo '#!/bin/sh\nkubectl krew __complete \"\$@\"' > $HOME/.krew/bin/kubectl_complete-krew;
    chmod +x $HOME/.krew/bin/kubectl_complete-krew" \
    atpull"%atclone" \
    run-atpull \
    z-shell/null

@vrej-abramian
Copy link

With the latest kubectl version (1.26), the kubectl plugins completion now works!

To enable completion for kubectl krew, run the following commands:

echo '#!/bin/sh\nkubectl krew __complete "$@"' >~/.krew/bin/kubectl_complete-krew
chmod u+x ~/.krew/bin/kubectl_complete-krew

@maelvls this is how it works for me and thank you for the hack ))
echo -e '#!/bin/bash\nkubectl krew __complete "$@"' >~/.krew/bin/kubectl_complete-krew
chmod u+x ~/.krew/bin/kubectl_complete-krew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants