evanlucas / fish-kubectl-completions

kubectl completions for fish shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include support for the `--kubeconfig PATH` flag

JonParton opened this issue ยท comments

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! ๐Ÿ‘๐Ÿ‘

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!

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

@evanlucas - Pull request above that closes this feature request for your review! ๐Ÿ‘๐Ÿผ