9730915910c6cc7640f8af6063ffb93becf0414a

Author
Artem Babii <arthem.babij@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(kube-ps1): add symlink support (#12208)

Diff

 1diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md
 2index 1ed3e4438d16e7f304d4cf24cd8045f49635feaa..dd49eff39967c5d0b3c1dda0ec7351c2b7df428d 100644
 3--- a/plugins/kube-ps1/README.md
 4+++ b/plugins/kube-ps1/README.md
 5@@ -136,6 +136,7 @@ the following environment variables:
 6 | `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |
 7 | `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed |
 8 | `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed |
 9+| `KUBE_PS1_KUBECONFIG_SYMLINK` | `false` | Treat `KUBECONFIG` and `~/.kube/config` files as symbolic links |
10 
11 For terminals that do not support UTF-8, the symbol will be replaced with the
12 string `k8s`.
13diff --git a/plugins/kube-ps1/kube-ps1.plugin.zsh b/plugins/kube-ps1/kube-ps1.plugin.zsh
14index 894e0f7f04d3183a7507f2b126aa3a346ff1d54c..7edc62de8c91e0461f83f473eac74b3436c2b07c 100644
15--- a/plugins/kube-ps1/kube-ps1.plugin.zsh
16+++ b/plugins/kube-ps1/kube-ps1.plugin.zsh
17@@ -40,6 +40,7 @@ KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}"
18 KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}"
19 
20 KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
21+KUBE_PS1_KUBECONFIG_SYMLINK="${KUBE_PS1_KUBECONFIG_SYMLINK:-false}"
22 KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
23 KUBE_PS1_LAST_TIME=0
24 KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}"
25@@ -190,14 +191,26 @@ _kube_ps1_file_newer_than() {
26   local file=$1
27   local check_time=$2
28 
29-  if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
30-    mtime=$(zstat +mtime "${file}")
31-  elif stat -c "%s" /dev/null &> /dev/null; then
32-    # GNU stat
33-    mtime=$(stat -L -c %Y "${file}")
34+  if [[ "${KUBE_PS1_KUBECONFIG_SYMLINK}" == "true" ]]; then
35+    if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
36+      mtime=$(zstat -L +mtime "${file}")
37+    elif stat -c "%s" /dev/null &> /dev/null; then
38+      # GNU stat
39+      mtime=$(stat -c %Y "${file}")
40+    else
41+      # BSD stat
42+      mtime=$(stat -f %m "$file")
43+    fi
44   else
45-    # BSD stat
46-    mtime=$(stat -L -f %m "$file")
47+    if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
48+      mtime=$(zstat +mtime "${file}")
49+    elif stat -c "%s" /dev/null &> /dev/null; then
50+      # GNU stat
51+      mtime=$(stat -L -c %Y "${file}")
52+    else
53+      # BSD stat
54+      mtime=$(stat -L -f %m "$file")
55+    fi
56   fi
57 
58   [[ "${mtime}" -gt "${check_time}" ]]