2022-01-04 18:38:53 +08:00
|
|
|
typeset -g -A kubectx_mapping
|
2021-06-13 23:23:13 +08:00
|
|
|
|
|
|
|
function kubectx_prompt_info() {
|
2022-01-03 21:03:36 +08:00
|
|
|
(( $+commands[kubectl] )) || return
|
|
|
|
|
2022-02-11 00:00:45 +08:00
|
|
|
local current_ctx=$(kubectl config current-context 2> /dev/null)
|
|
|
|
|
|
|
|
[[ -n "$current_ctx" ]] || return
|
2022-01-03 21:03:36 +08:00
|
|
|
|
|
|
|
# use value in associative array if it exists
|
|
|
|
# otherwise fall back to the context name
|
2024-02-03 00:12:36 +08:00
|
|
|
echo "${kubectx_mapping[\"$current_ctx\"]:-${current_ctx:gs/%/%%}}"
|
2021-06-13 23:23:13 +08:00
|
|
|
}
|