diff --git a/README.md b/README.md index e6b8535..ef753a8 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/kube-ps1.sh b/kube-ps1.sh index 3be66c8..2e5de3d 100644 --- a/kube-ps1.sh +++ b/kube-ps1.sh @@ -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" @@ -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}" ]]