Skip to content

Commit f0e2160

Browse files
authored
chore(kube-ps1): update to e19c9ee8 (ohmyzsh#13666)
Co-authored-by: ohmyzsh[bot] <54982679+ohmyzsh[bot]@users.noreply.github.com>
1 parent 9e2c154 commit f0e2160

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

.github/dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies:
3030
plugins/kube-ps1:
3131
repo: jonmosco/kube-ps1
3232
branch: master
33-
version: 9b41c091d5dd4a99e58cf58b5d98a4847937b1bb
33+
version: e19c9ee867c5655814c384a6bf543e330e6ef1b7
3434
precopy: |
3535
set -e
3636
find . ! -name kube-ps1.sh ! -name LICENSE ! -name README.md -delete

plugins/kube-ps1/kube-ps1.plugin.zsh

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ _kube_ps1_shell_type() {
5555
_kube_ps1_init() {
5656
[[ -f "${_KUBE_PS1_DISABLE_PATH}" ]] && KUBE_PS1_ENABLED=off
5757

58-
case "$(_kube_ps1_shell_type)" in
58+
# Detect shell type once and cache it
59+
_KUBE_PS1_SHELL="$(_kube_ps1_shell_type)"
60+
61+
# Check tput availability once
62+
if tput setaf 1 &> /dev/null; then
63+
_KUBE_PS1_TPUT_AVAILABLE=true
64+
else
65+
_KUBE_PS1_TPUT_AVAILABLE=false
66+
fi
67+
68+
case "${_KUBE_PS1_SHELL}" in
5969
"zsh")
6070
_KUBE_PS1_OPEN_ESC="%{"
6171
_KUBE_PS1_CLOSE_ESC="%}"
@@ -96,10 +106,10 @@ _kube_ps1_color_fg() {
96106
if [[ "${_KUBE_PS1_FG_CODE}" == "default" ]]; then
97107
_KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
98108
return
99-
elif [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
109+
elif [[ "${_KUBE_PS1_SHELL}" == "zsh" ]]; then
100110
_KUBE_PS1_FG_CODE="%F{$_KUBE_PS1_FG_CODE}"
101-
elif [[ "$(_kube_ps1_shell_type)" == "bash" ]]; then
102-
if tput setaf 1 &> /dev/null; then
111+
elif [[ "${_KUBE_PS1_SHELL}" == "bash" ]]; then
112+
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
103113
_KUBE_PS1_FG_CODE="$(tput setaf "${_KUBE_PS1_FG_CODE}")"
104114
elif [[ $_KUBE_PS1_FG_CODE -ge 0 ]] && [[ $_KUBE_PS1_FG_CODE -le 256 ]]; then
105115
_KUBE_PS1_FG_CODE="\033[38;5;${_KUBE_PS1_FG_CODE}m"
@@ -129,15 +139,15 @@ _kube_ps1_color_bg() {
129139
if [[ "${_KUBE_PS1_BG_CODE}" == "default" ]]; then
130140
_KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_BG}"
131141
return
132-
elif [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
142+
elif [[ "${_KUBE_PS1_SHELL}" == "zsh" ]]; then
133143
_KUBE_PS1_BG_CODE="%K{$_KUBE_PS1_BG_CODE}"
134-
elif [[ "$(_kube_ps1_shell_type)" == "bash" ]]; then
135-
if tput setaf 1 &> /dev/null; then
144+
elif [[ "${_KUBE_PS1_SHELL}" == "bash" ]]; then
145+
if [[ "${_KUBE_PS1_TPUT_AVAILABLE}" == "true" ]]; then
136146
_KUBE_PS1_BG_CODE="$(tput setab "${_KUBE_PS1_BG_CODE}")"
137147
elif [[ $_KUBE_PS1_BG_CODE -ge 0 ]] && [[ $_KUBE_PS1_BG_CODE -le 256 ]]; then
138148
_KUBE_PS1_BG_CODE="\033[48;5;${_KUBE_PS1_BG_CODE}m"
139149
else
140-
_KUBE_PS1_BG_CODE="${DEFAULT_BG}"
150+
_KUBE_PS1_BG_CODE="${_KUBE_PS1_DEFAULT_BG}"
141151
fi
142152
fi
143153
echo "${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_BG_CODE}${_KUBE_PS1_CLOSE_ESC}"
@@ -174,7 +184,7 @@ _kube_ps1_symbol() {
174184
symbol="$(_kube_ps1_color_fg ${oc_symbol_color})${oc_glyph}${KUBE_PS1_RESET_COLOR}"
175185
;;
176186
*)
177-
case "$(_kube_ps1_shell_type)" in
187+
case "${_KUBE_PS1_SHELL}" in
178188
bash)
179189
if ((BASH_VERSINFO[0] >= 4)) && [[ $'\u2388' != "\\u2388" ]]; then
180190
symbol="$(_kube_ps1_color_fg $custom_symbol_color)${symbol_default}${KUBE_PS1_RESET_COLOR}"
@@ -212,7 +222,7 @@ _kube_ps1_file_newer_than() {
212222
local file=$1
213223
local check_time=$2
214224

215-
if [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
225+
if [[ "${_KUBE_PS1_SHELL}" == "zsh" ]]; then
216226
# Use zstat '-F %s.%s' to make it compatible with low zsh version (eg: 5.0.2)
217227
mtime=$(zstat -L +mtime -F %s.%s "${file}")
218228
elif stat -c "%s" /dev/null &> /dev/null; then
@@ -292,13 +302,13 @@ _kube_ps1_get_ns() {
292302

293303
_kube_ps1_get_context_ns() {
294304
# Set the command time
295-
if [[ "$(_kube_ps1_shell_type)" == "bash" ]]; then
305+
if [[ "${_KUBE_PS1_SHELL}" == "bash" ]]; then
296306
if ((BASH_VERSINFO[0] >= 4 && BASH_VERSINFO[1] >= 2)); then
297307
_KUBE_PS1_LAST_TIME=$(printf '%(%s)T')
298308
else
299309
_KUBE_PS1_LAST_TIME=$(date +%s)
300310
fi
301-
elif [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
311+
elif [[ "${_KUBE_PS1_SHELL}" == "zsh" ]]; then
302312
_KUBE_PS1_LAST_TIME=$EPOCHREALTIME
303313
fi
304314

@@ -325,7 +335,7 @@ Toggle kube-ps1 prompt on
325335
326336
Usage: kubeon [-g | --global] [-h | --help]
327337
328-
With no arguments, turn oon kube-ps1 status for this shell instance (default).
338+
With no arguments, turn on kube-ps1 status for this shell instance (default).
329339
330340
-g --global turn on kube-ps1 status globally
331341
-h --help print this message

0 commit comments

Comments
 (0)