kubectx.plugin.zsh 517 B

123456789101112131415
  1. typeset -g -A kubectx_mapping
  2. function kubectx_prompt_info() {
  3. (( $+commands[kubectl] )) || return
  4. local current_ctx=$(kubectl config current-context 2> /dev/null)
  5. [[ -n "$current_ctx" ]] || return
  6. # Use value in associative array if it exists, otherwise fall back to the context name
  7. #
  8. # Note: we need to escape the % character in the prompt string when coming directly from
  9. # the context name, as it could contain a % character.
  10. echo "${kubectx_mapping[$current_ctx]:-${current_ctx:gs/%/%%}}"
  11. }