From 653ac5b89bff5528cdca4e20314229294834f2ce Mon Sep 17 00:00:00 2001 From: AngeD Date: Mon, 12 Dec 2022 16:43:14 +0100 Subject: [PATCH] feat: custom p10k inspired kubectl PS1 --- .config/zsh/.zshrc | 2 +- .../zsh/custom/themes/simpletheme.zsh-theme | 39 +++++++++++++++---- .config/zsh/ohmyzsh | 2 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 599fd8b..1e96057 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -70,7 +70,7 @@ zstyle ':omz:update' mode disabled # disable automatic updates # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. -plugins=(vi-mode colored-man-pages kube-ps1 timer git gitignore) +plugins=(vi-mode colored-man-pages git gitignore) . "$ZSH"/oh-my-zsh.sh diff --git a/.config/zsh/custom/themes/simpletheme.zsh-theme b/.config/zsh/custom/themes/simpletheme.zsh-theme index e9409b9..6da9595 100644 --- a/.config/zsh/custom/themes/simpletheme.zsh-theme +++ b/.config/zsh/custom/themes/simpletheme.zsh-theme @@ -1,13 +1,36 @@ -PROMPT=' -$(kube_ps1) -%(?::%{$fg_bold[red]%}%? )%{$fg_bold[cyan]%}%~%{$reset_color%} $(git_prompt_info)' +KUBE_PS1_KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" +KUBE_PS1_KUBECONFIGMD5= +KUBE_PS1_CTX= +KUBE_PS1_NS= + +_update_KUBE_PS1() { + local md5="$(md5sum $KUBE_PS1_KUBECONFIG)" + + [[ "$md5" == "$KUBE_PS1_KUBECONFIGMD5" ]] && return + + KUBE_PS1_KUBECONFIGMD5="$md5" + KUBE_PS1_CTX="$(kubectl config current-context)" + KUBE_PS1_NS="$(kubectl config view --minify -o jsonpath='{..namespace}')" +} + +precmd() { + _update_KUBE_PS1 + local ctx="$KUBE_PS1_CTX" + local ns="$KUBE_PS1_NS" + local symbol='\u2388 ' + local sep='/' + local bg='\e[45m' + local reset='\e[0m' + #local end=" $reset\e[35m\ue0b4" #  + #local end=" $reset\e[35m\ue0bc" #  + local end=" $reset\e[35m\ue0b0" #  + + echo "$bg$symbol$ctx$sep$ns$end$reset" +} + +PROMPT='%(?::%{$fg_bold[red]%}%? )%{$fg_bold[cyan]%}%~%{$reset_color%} $(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" - -KUBE_PS1_PREFIX= -KUBE_PS1_SEPARATOR=' ' -KUBE_PS1_DIVIDER=/ -KUBE_PS1_SUFFIX= diff --git a/.config/zsh/ohmyzsh b/.config/zsh/ohmyzsh index f4dc8c5..29cf199 160000 --- a/.config/zsh/ohmyzsh +++ b/.config/zsh/ohmyzsh @@ -1 +1 @@ -Subproject commit f4dc8c5be365668810783ced01a86ff8f251bfd7 +Subproject commit 29cf199b5d84eb4897f2e0e421a344174568eb9f