evanlucas / fish-kubectl-completions

kubectl completions for fish shell
MIT License
576 stars 42 forks source link

Include support for the `--kubeconfig PATH` flag #37

Closed JonParton closed 3 years ago

JonParton commented 3 years ago

Currently if you are using kubectl with the --kubeconfig PATH flag to specify a different kubeconfig file autocompletion ignores this and still uses the normal kubectl context.

I see In the code the completions account for other flags such as the context so it may not be a huge stretch to add this also?

Thoughts?

P. S. Thank you for putting effort into these amazing completions that save oodles of time! 👍👍

JonParton commented 3 years ago

I think I can see how this can be done really easily by duplicating your existing code for the context flags.

function __fish_kubectl_get_kubeconfig_flags
    set -l cmd (commandline -opc)
    if [ (count $cmd) -eq 0 ]
        return 1
    end

    set -l foundKubeconfig 0

    for c in $cmd
        test $foundKubeconfig -eq 1
        set -l out "--kubeconfig" "$c"
        and echo $out
        and return 0

        if string match -q -r -- "--kubeconfig=" "$c"
            set -l out (string split -- "=" "$c" | string join " ")
            and echo $out
            and return 0
        else if contains -- "$c" "--kubeconfig"
            set foundKubeconfig 1
        end
    end

    return 1
end

And implement the above in the fish kubectl function alongside the context args.

I'll do a pull request in the morning for you to review!

JonParton commented 3 years ago

Noticed from a previously closed pull request that this should now be done in the main.go file!

JonParton commented 3 years ago

@evanlucas - Pull request above that closes this feature request for your review! 👍🏼