Skip to content

Instantly share code, notes, and snippets.

@msiegenthaler
Last active June 29, 2018 08:21
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 kubernetes_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 $namespace
[ -z $ns ]; and set -l ns (kubectl config view -o json | jq --arg context $ctx -r '.contexts[] | select(.name | contains($context)) | .context.namespace')
[ -z $ns ]; and set -l ns 'default'
echo (set_color 666666)"$ctx$KUBECTL_PROMPT_SEPARATOR$ns"
end
function enable_kubernetes
function fish_right_prompt
echo (kubernetes_status)
end
end
function k --wraps kubectl
set -l cmd
if test -n "$argv"
set cmd $argv
else if [ (tput cols) -lt 150 ]
set cmd get pod
else
set cmd get pod -o wide
end
if test -n "$namespace"
kubectl --namespace "$namespace" $cmd
else
kubectl $cmd
end
end
function secret
set -l secret $argv[1]
set -l value $argv[2]
if test -z $secret; or test -z $value
echo "Usage: secret <secret> <value>"
return 121
end
k get secret "$secret" -o jsonpath=\{.data.$value\} | base64 -d
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment