Skip to content

Commit

Permalink
fix some quoting, remove 2 more var statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmosco committed May 17, 2024
1 parent 5aaaee3 commit 0ee5524
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions kube-ps1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ KUBE_PS1_SEPARATOR="${KUBE_PS1_SEPARATOR-|}"
KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}"
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"

KUBE_PS1_CTX_COLOR="${KUBE_PS1_CTX_COLOR-red}"
KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}"

_KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
_KUBE_PS1_LAST_TIME=0
Expand Down Expand Up @@ -100,14 +97,14 @@ _kube_ps1_color_fg() {
_KUBE_PS1_FG_CODE="%F{$_KUBE_PS1_FG_CODE}"
elif [[ "$(_kube_ps1_shell_type)" == "bash" ]]; then
if tput setaf 1 &> /dev/null; then
_KUBE_PS1_FG_CODE="$(tput setaf ${_KUBE_PS1_FG_CODE})"
_KUBE_PS1_FG_CODE="$(tput setaf "${_KUBE_PS1_FG_CODE}")"
elif [[ $_KUBE_PS1_FG_CODE -ge 0 ]] && [[ $_KUBE_PS1_FG_CODE -le 256 ]]; then
_KUBE_PS1_FG_CODE="\033[38;5;${_KUBE_PS1_FG_CODE}m"
else
_KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
fi
fi
echo ${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_FG_CODE}${_KUBE_PS1_CLOSE_ESC}
echo "${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_FG_CODE}${_KUBE_PS1_CLOSE_ESC}"
}

_kube_ps1_color_bg() {
Expand All @@ -133,14 +130,14 @@ _kube_ps1_color_bg() {
_KUBE_PS1_BG_CODE="%K{$_KUBE_PS1_BG_CODE}"
elif [[ "$(_kube_ps1_shell_type)" == "bash" ]]; then
if tput setaf 1 &> /dev/null; then
_KUBE_PS1_BG_CODE="$(tput setab ${_KUBE_PS1_BG_CODE})"
_KUBE_PS1_BG_CODE="$(tput setab "${_KUBE_PS1_BG_CODE}")"
elif [[ $_KUBE_PS1_BG_CODE -ge 0 ]] && [[ $_KUBE_PS1_BG_CODE -le 256 ]]; then
_KUBE_PS1_BG_CODE="\033[48;5;${_KUBE_PS1_BG_CODE}m"
else
_KUBE_PS1_BG_CODE="${DEFAULT_BG}"
fi
fi
echo ${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_BG_CODE}${_KUBE_PS1_CLOSE_ESC}
echo "${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_BG_CODE}${_KUBE_PS1_CLOSE_ESC}"
}

_kube_ps1_binary_check() {
Expand Down Expand Up @@ -272,7 +269,7 @@ _kube_ps1_get_context() {
KUBE_PS1_CONTEXT="${KUBE_PS1_CONTEXT:-N/A}"

if [[ -n "${KUBE_PS1_CLUSTER_FUNCTION}" ]]; then
KUBE_PS1_CONTEXT=$($KUBE_PS1_CLUSTER_FUNCTION $KUBE_PS1_CONTEXT)
KUBE_PS1_CONTEXT="$("${KUBE_PS1_CLUSTER_FUNCTION}" "${KUBE_PS1_CONTEXT}")"
fi
fi
}
Expand All @@ -283,7 +280,7 @@ _kube_ps1_get_ns() {
KUBE_PS1_NAMESPACE="${KUBE_PS1_NAMESPACE:-N/A}"

if [[ -n "${KUBE_PS1_NAMESPACE_FUNCTION}" ]]; then
KUBE_PS1_NAMESPACE=$($KUBE_PS1_NAMESPACE_FUNCTION $KUBE_PS1_NAMESPACE)
KUBE_PS1_NAMESPACE="$("${KUBE_PS1_NAMESPACE_FUNCTION}" "${KUBE_PS1_NAMESPACE}")"
fi
fi
}
Expand Down Expand Up @@ -399,15 +396,15 @@ kube_ps1() {

# Context
if [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
KUBE_PS1+="$(_kube_ps1_color_fg "${KUBE_PS1_CTX_COLOR}")${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}"
KUBE_PS1+="$(_kube_ps1_color_fg "${KUBE_PS1_CTX_COLOR:-red}")${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}"
fi

# Namespace
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then
if [[ -n "${KUBE_PS1_DIVIDER}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then
KUBE_PS1+="${KUBE_PS1_DIVIDER}"
fi
KUBE_PS1+="$(_kube_ps1_color_fg "${KUBE_PS1_NS_COLOR}")${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}"
KUBE_PS1+="$(_kube_ps1_color_fg "${KUBE_PS1_NS_COLOR:-cyan}")${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}"
fi

# Suffix
Expand Down

0 comments on commit 0ee5524

Please sign in to comment.