1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 10:22:00 +00:00

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

This commit is contained in:
Artem Babii 2024-02-29 23:07:10 +02:00 committed by GitHub
parent 50fd98e5a6
commit 9730915910
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 7 deletions

View file

@ -136,6 +136,7 @@ the following environment variables:
| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character | | `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_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_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 For terminals that do not support UTF-8, the symbol will be replaced with the
string `k8s`. string `k8s`.

View file

@ -40,6 +40,7 @@ KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}"
KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}" KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}"
KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}" 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_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
KUBE_PS1_LAST_TIME=0 KUBE_PS1_LAST_TIME=0
KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}" KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}"
@ -190,6 +191,17 @@ _kube_ps1_file_newer_than() {
local file=$1 local file=$1
local check_time=$2 local check_time=$2
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
if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
mtime=$(zstat +mtime "${file}") mtime=$(zstat +mtime "${file}")
elif stat -c "%s" /dev/null &> /dev/null; then elif stat -c "%s" /dev/null &> /dev/null; then
@ -199,6 +211,7 @@ _kube_ps1_file_newer_than() {
# BSD stat # BSD stat
mtime=$(stat -L -f %m "$file") mtime=$(stat -L -f %m "$file")
fi fi
fi
[[ "${mtime}" -gt "${check_time}" ]] [[ "${mtime}" -gt "${check_time}" ]]
} }