summaryrefslogtreecommitdiff
path: root/plugins/kube-ps1
diff options
context:
space:
mode:
authorArtem Babii <arthem.babij@gmail.com>2024-02-29 23:07:10 +0200
committerGitHub <noreply@github.com>2024-02-29 22:07:10 +0100
commit9730915910c6cc7640f8af6063ffb93becf0414a (patch)
treed58676973c95e332c92d3e4af44c373e05670f5d /plugins/kube-ps1
parent50fd98e5a6c9d7c36b0cc678f577f7ce1d181bea (diff)
downloadzsh-9730915910c6cc7640f8af6063ffb93becf0414a.tar.gz
zsh-9730915910c6cc7640f8af6063ffb93becf0414a.tar.bz2
zsh-9730915910c6cc7640f8af6063ffb93becf0414a.zip
feat(kube-ps1): add symlink support (#12208)
Diffstat (limited to 'plugins/kube-ps1')
-rw-r--r--plugins/kube-ps1/README.md1
-rw-r--r--plugins/kube-ps1/kube-ps1.plugin.zsh27
2 files changed, 21 insertions, 7 deletions
diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md
index 1ed3e4438..dd49eff39 100644
--- a/plugins/kube-ps1/README.md
+++ b/plugins/kube-ps1/README.md
@@ -136,6 +136,7 @@ the following environment variables:
| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |
| `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_KUBECONFIG_SYMLINK` | `false` | Treat `KUBECONFIG` and `~/.kube/config` files as symbolic links |
For terminals that do not support UTF-8, the symbol will be replaced with the
string `k8s`.
diff --git a/plugins/kube-ps1/kube-ps1.plugin.zsh b/plugins/kube-ps1/kube-ps1.plugin.zsh
index 894e0f7f0..7edc62de8 100644
--- a/plugins/kube-ps1/kube-ps1.plugin.zsh
+++ b/plugins/kube-ps1/kube-ps1.plugin.zsh
@@ -40,6 +40,7 @@ KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}"
KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}"
KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
+KUBE_PS1_KUBECONFIG_SYMLINK="${KUBE_PS1_KUBECONFIG_SYMLINK:-false}"
KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
KUBE_PS1_LAST_TIME=0
KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}"
@@ -190,14 +191,26 @@ _kube_ps1_file_newer_than() {
local file=$1
local check_time=$2
- if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
- mtime=$(zstat +mtime "${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}" == "zsh" ]]; then
+ mtime=$(zstat -L +mtime "${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}" == "zsh" ]]; then
+ mtime=$(zstat +mtime "${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}" ]]