summaryrefslogtreecommitdiff
path: root/plugins/kubectx/kubectx.plugin.zsh
blob: f1ca990ad923851576ca1a9a63d96260af8e62b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typeset -g -A kubectx_mapping

function kubectx_prompt_info() {
  (( $+commands[kubectl] )) || return

  local current_ctx=$(kubectl config current-context 2> /dev/null)

  [[ -n "$current_ctx" ]] || return

  # Use value in associative array if it exists, otherwise fall back to the context name
  #
  # Note: we need to escape the % character in the prompt string when coming directly from
  # the context name, as it could contain a % character.
  echo "${kubectx_mapping[$current_ctx]:-${current_ctx:gs/%/%%}}"
}