Skip to content

Instantly share code, notes, and snippets.

@msiegenthaler
Last active September 16, 2024 13:57
Show Gist options
  • Save msiegenthaler/e32d60683ce74410ec79736e246adec7 to your computer and use it in GitHub Desktop.
Save msiegenthaler/e32d60683ce74410ec79736e246adec7 to your computer and use it in GitHub Desktop.
Fish Shell function to display the kubernetes namespace to the right
function kubectl_status
[ -z "$KUBECTL_PROMPT_SEPARATOR" ]; and set -l KUBECTL_PROMPT_SEPARATOR "/"
set -l config $KUBECONFIG
[ -z "$config" ]; and set -l config "$HOME/.kube/config"
if [ ! -f $config ]
echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no config"
return
end
set -l ctx (kubectl config current-context 2>/dev/null)
if [ $status -ne 0 ]
echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no context"
return
end
set -l ns (kubectl config view -o json | jq --arg context $context -r '.contexts[] | select(.name | contains($context)) | .context.namespace')
[ -z $ns ]; and set -l ns 'default'
echo (set_color 999999)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
end
function fish_right_prompt
echo (kubectl_status)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment