refreshed dotfiles
This commit is contained in:
@@ -43,5 +43,44 @@ case $_distro in
|
||||
*) ICON="";;
|
||||
esac
|
||||
|
||||
# Kubernetes integration
|
||||
function update_kubernetes_context() {
|
||||
if command -v kubectl &> /dev/null; then
|
||||
KUBE_CTX=$(kubectl config current-context 2>/dev/null)
|
||||
if [ $? -eq 0 ]; then
|
||||
KUBE_NS=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)
|
||||
export STARSHIP_KUBERNETES_CONTEXT="$KUBE_CTX"
|
||||
[ -n "$KUBE_NS" ] && export STARSHIP_KUBERNETES_NAMESPACE="$KUBE_NS"
|
||||
else
|
||||
unset STARSHIP_KUBERNETES_CONTEXT
|
||||
unset STARSHIP_KUBERNETES_NAMESPACE
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Update kubernetes context on startup
|
||||
update_kubernetes_context
|
||||
|
||||
# Function to wrap kubectl and update context when needed
|
||||
function kubectl() {
|
||||
command kubectl "$@"
|
||||
local exit_code=$?
|
||||
|
||||
# Update context if the command was successful and changed the context or namespace
|
||||
if [ $exit_code -eq 0 ] && [[ "$1" == "config" && ("$2" == "use-context" || "$2" == "set-context") ]]; then
|
||||
update_kubernetes_context
|
||||
fi
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
# 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'
|
||||
|
||||
export STARSHIP_DISTRO="$ICON"
|
||||
export STARSHIP_DEVICE="$DEVICE"
|
||||
export STARSHIP_DEVICE="$DEVICE"
|
||||
|
||||
Reference in New Issue
Block a user