43 lines
1.2 KiB
Fish
43 lines
1.2 KiB
Fish
# Kubernetes setup
|
|
set -gx KUBECONFIG ~/.kube/config
|
|
|
|
# Kubernetes aliases
|
|
alias k="kubectl"
|
|
alias kgp="kubectl get pods"
|
|
alias kgn="kubectl get nodes"
|
|
alias kgs="kubectl get services"
|
|
alias kgc="kubectl config get-contexts"
|
|
alias kuc="kubectl config use-context"
|
|
alias kns="kubectl config set-context --current --namespace"
|
|
|
|
# Kubernetes context function
|
|
function update_kubernetes_context
|
|
if command -q kubectl
|
|
set -l kube_ctx (kubectl config current-context 2>/dev/null)
|
|
if test $status -eq 0
|
|
set -l kube_ns (kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)
|
|
set -gx STARSHIP_KUBERNETES_CONTEXT $kube_ctx
|
|
if test -n "$kube_ns"
|
|
set -gx STARSHIP_KUBERNETES_NAMESPACE $kube_ns
|
|
end
|
|
else
|
|
set -e STARSHIP_KUBERNETES_CONTEXT
|
|
set -e STARSHIP_KUBERNETES_NAMESPACE
|
|
end
|
|
end
|
|
end
|
|
|
|
# Wrapper for kubectl
|
|
function kubectl
|
|
command kubectl $argv
|
|
set -l exit_code $status
|
|
|
|
if test $exit_code -eq 0; and test "$argv[1]" = "config"; and contains "$argv[2]" "use-context" "set-context"
|
|
update_kubernetes_context
|
|
end
|
|
return $exit_code
|
|
end
|
|
|
|
# Update context on startup
|
|
update_kubernetes_context
|