Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ the following variables:
| `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed |
| `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed |
| `KUBE_PS1_HIDE_IF_NOCONTEXT` | `false` | Hide the kube-ps1 prompt if no context is set |
| `KUBE_PS1_KUBECONFIG_SYMLINK` | `false` | Treat `KUBECONFIG` and `~/.kube/config` files as symbolic links |

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

Expand Down
30 changes: 22 additions & 8 deletions kube-ps1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}"
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"

KUBE_PS1_HIDE_IF_NOCONTEXT="${KUBE_PS1_HIDE_IF_NOCONTEXT:-false}"
KUBE_PS1_KUBECONFIG_SYMLINK="${KUBE_PS1_KUBECONFIG_SYMLINK:-false}"

_KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
_KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
Expand Down Expand Up @@ -212,15 +213,28 @@ _kube_ps1_file_newer_than() {
local file=$1
local check_time=$2

if [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
# Use zstat '-F %s.%s' to make it compatible with low zsh version (eg: 5.0.2)
mtime=$(zstat +mtime -F %s.%s "${file}")
elif stat -c "%s" /dev/null &> /dev/null; then
# GNU stat
mtime=$(stat -L -c %Y "${file}")
if [[ "${KUBE_PS1_KUBECONFIG_SYMLINK}" == "true" ]]; then
if [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
# Use zstat '-F %s.%s' to make it compatible with low zsh version (eg: 5.0.2)
mtime=$(zstat -L +mtime -F %s.%s "${file}")
elif stat -c "%s" /dev/null &> /dev/null; then
# GNU stat
mtime=$(stat -c %Y "${file}")
else
# BSD stat
mtime=$(stat -f %m "$file")
fi
else
# BSD stat
mtime=$(stat -L -f %m "$file")
if [[ "$(_kube_ps1_shell_type)" == "zsh" ]]; then
# Use zstat '-F %s.%s' to make it compatible with low zsh version (eg: 5.0.2)
mtime=$(zstat +mtime -F %s.%s "${file}")
elif stat -c "%s" /dev/null &> /dev/null; then
# GNU stat
mtime=$(stat -L -c %Y "${file}")
else
# BSD stat
mtime=$(stat -L -f %m "$file")
fi
fi

[[ "${mtime}" -gt "${check_time}" ]]
Expand Down