Skip to content

Instantly share code, notes, and snippets.

@marinho
Last active November 28, 2024 07:27
Show Gist options
  • Save marinho/44f8cc3aa1f5fd949daf8be2054b6261 to your computer and use it in GitHub Desktop.
Save marinho/44f8cc3aa1f5fd949daf8be2054b6261 to your computer and use it in GitHub Desktop.
Fish scripts to set kubectl and k9s to use kubeconfig from current directory
function find-kubeconfig
set dir (pwd)
while true
if test -d "$dir/.kube"
echo "$dir/.kube"
return
end
if test "$dir" = "/"
break
end
set dir (dirname $dir)
end
# Return nothing if no kubeconfig.yaml is found
echo ""
end
function k9s
set kubedir (find-kubeconfig)
set kubeconfig "$kubedir/config"
if test -n "$kubeconfig"
set KUBECONFIG $kubeconfig
end
command k9s $argv
end
function kubectl
set kubedir (find-kubeconfig)
set kubeconfig "$kubedir/config"
set kubecache "$kubedir/cache"
if test -n "$kubeconfig"
set KUBECONFIG $kubeconfig
command kubectl $argv --cache-dir="$kubecache"
else
command kubectl $argv
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment