feature: add bash completion for plugin mode of kubectl ctx and kubectl ns
if added to PATH and name kubectl_complete-ns and kubectl_complete-ctx these two script provide completion for ns and ctx cli in kubectl plugin mode
if this pull request is good to merge i could made another one on krew-index project to adapt the two manifest like this :
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: ns
spec:
homepage: https://github.com/ahmetb/kubectx
shortDescription: Switch between Kubernetes namespaces
version: v0.9.4
description: |
Also known as "kubens", a utility to set your current namespace and switch
between them.
caveats: |
If fzf is installed on your machine, you can interactively choose
between the entries using the arrow keys, or by fuzzy searching
as you type.
To enable completion run add "$KREW_ROOT/store/ns/v0.9.4/completion/" to your PATH
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/ahmetb/kubectx/archive/v0.9.4.tar.gz
sha256: e50b72a37d01cc4b2c7d51b8f2167de518031b0c013bcb0b82c036d5ad1d1926
bin: kubens
files:
- from: kubectx-*/kubens
to: .
- from: kubectx-*/LICENSE
to: .
- from: kubectx-*/completion/plugins/kubectl_complete-ns
to: completion
ps : maybe some change should be done to made this bash agnostic
Nice, but I'm trying to see if we can provide a straightforward way in krew manifests to let plugins configure how their binary is linked for completions.
For kubectx, since we're moving away from bash implementations to Go based implementations, completions might make sense to implement as a hidden subcommand. It might take me a while to get back to this.
kubectl completion for plugin call a binary named kubectl_complete-<pluginName> so i think hidden command would not work. But yes maybe a go binary is better to benefit of classical application function.
I thought of another solution for link completion in krew with existing manifest but it doesn't work. This solution was to create link from $KREW_ROOT/store/kubectl_complete-<pluginName> to $KREW_ROOT/bin/ but krew create only one link currently. Feel free to refuse this pull request i do this more for me than for particular contribution 🙂