2022-01-04 10:38:53 +00:00
|
|
|
typeset -g -A kubectx_mapping
|
2021-06-13 15:23:13 +00:00
|
|
|
|
|
|
|
function kubectx_prompt_info() {
|
2022-01-03 13:03:36 +00:00
|
|
|
(( $+commands[kubectl] )) || return
|
|
|
|
|
2022-02-10 16:00:45 +00:00
|
|
|
local current_ctx=$(kubectl config current-context 2> /dev/null)
|
|
|
|
|
|
|
|
[[ -n "$current_ctx" ]] || return
|
2022-01-03 13:03:36 +00:00
|
|
|
|
2024-08-01 08:00:58 +00:00
|
|
|
# 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/%/%%}}"
|
2021-06-13 15:23:13 +00:00
|
|
|
}
|