Files
dotfiles/.zsh/starship.zsh
2025-01-05 12:01:29 +01:00

87 lines
2.9 KiB
Bash

# find out which distribution we are running on
LFILE="/etc/*-release"
MFILE="/System/Library/CoreServices/SystemVersion.plist"
if [[ -f $LFILE ]]; then
_distro=$(awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }')
elif [[ -f $MFILE ]]; then
_distro="macos"
# on mac os use the systemprofiler to determine the current model
_device=$(system_profiler SPHardwareDataType | awk '/Model Name/ {print $3,$4,$5,$6,$7}')
case $_device in
*MacBook*) DEVICE="";;
*) DEVICE="";;
esac
fi
# set an icon based on the distro
# make sure your font is compatible with https://github.com/lukas-w/font-logos
case $_distro in
*kali*) ICON="ﴣ";;
*arch*) ICON="";;
*debian*) ICON="";;
*raspbian*) ICON="";;
*ubuntu*) ICON="";;
*elementary*) ICON="";;
*fedora*) ICON="";;
*coreos*) ICON="";;
*gentoo*) ICON="";;
*mageia*) ICON="";;
*centos*) ICON="";;
*opensuse*|*tumbleweed*) ICON="";;
*sabayon*) ICON="";;
*slackware*) ICON="";;
*linuxmint*) ICON="";;
*alpine*) ICON="";;
*aosc*) ICON="";;
*nixos*) ICON="";;
*devuan*) ICON="";;
*manjaro*) ICON="";;
*rhel*) ICON="";;
*macos*) ICON="";;
*) 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"