Skip to content

Instantly share code, notes, and snippets.

@roccozanni
Created August 18, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roccozanni/200ef1d1695bbdee585625b5b2cb3278 to your computer and use it in GitHub Desktop.
Save roccozanni/200ef1d1695bbdee585625b5b2cb3278 to your computer and use it in GitHub Desktop.
prompt_kubectl()
{
# Exit if kubectl is not configured
local kubectl_config="$HOME/.kube/config"
if [[ ! -a "$kubectl_config" ]]; then
return
fi
# Get current context
local kubectl_context=$(cat $kubectl_config | grep "current-context:" | sed "s/current-context: //")
if [[ -n $kubectl_context ]]; then
prompt_segment magenta black "K:$kubectl_context"
fi
}
@ultimateboy
Copy link

ultimateboy commented Nov 1, 2016

Thanks for this! I've made a few modifications.

  1. If the context is minikube, ensure the minikube vm is up.
  2. use the unicode helm symbol (⎈) instead of "K:"
  3. used a more neutral blue color instead of magenta
prompt_kubectl()
{
  # Exit if kubectl is not configured
  local kubectl_config="$HOME/.kube/config"
  if [[ ! -a "$kubectl_config" ]]; then
    return
  fi

  # Get current context
  local kubectl_context=$(cat $kubectl_config | grep "current-context:" | sed "s/current-context: //")
  if [[ -n $kubectl_context ]]; then
    # if context is minikube, ensure vm is up
    if [[ $kubectl_context == "minikube" ]]; then
      local minikube_status=$(minikube status --format={{.MinikubeStatus}})
      if [[ $minikube_status != "Running" ]] then
        return
      fi
    fi
    prompt_segment 111 black "\u2388  $kubectl_context"
  fi
}

@btopro
Copy link

btopro commented Nov 2, 2016

@ultimateboy where does this go in the zsh theme to apply it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment