Skip to content

Commit b6f5822

Browse files
authored
Merge pull request #198 from gitmpr/feat/hide-if-no-context
Add configuration option to hide kube-ps1 prompt if no context is set
2 parents b2286b6 + 85827b5 commit b6f5822

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ the following variables:
197197
| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |
198198
| `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed |
199199
| `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed |
200+
| `KUBE_PS1_HIDE_IF_NOCONTEXT` | `false` | Hide the kube-ps1 prompt if no context is set |
200201

201202
To disable a feature, set it to an empty string:
202203

kube-ps1.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ KUBE_PS1_SEPARATOR="${KUBE_PS1_SEPARATOR-|}"
3434
KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}"
3535
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"
3636

37+
KUBE_PS1_HIDE_IF_NOCONTEXT="${KUBE_PS1_HIDE_IF_NOCONTEXT:-false}"
38+
3739
_KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
3840
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
3941
_KUBE_PS1_LAST_TIME=0
@@ -376,6 +378,8 @@ kubeoff() {
376378
kube_ps1() {
377379
[[ "${KUBE_PS1_ENABLED}" == "off" ]] && return
378380
[[ -z "${KUBE_PS1_CONTEXT}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]] && return
381+
[[ "${KUBE_PS1_CONTEXT}" == "N/A" ]] && [[ ${KUBE_PS1_HIDE_IF_NOCONTEXT} == false ]] && return
382+
379383

380384
local KUBE_PS1
381385
local KUBE_PS1_RESET_COLOR="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_FG}${_KUBE_PS1_CLOSE_ESC}"

0 commit comments

Comments
 (0)