From 9a8a6ca836fa5cca5cd1f8d181a0281edc2712a5 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 7 Sep 2019 10:05:56 +0200 Subject: [PATCH] allow prompt segments to be disabled through configuration options Prompt segment `foo` doesn't get evaluated or shown on the left if `${POWERLEVEL9K_FOO_LEFT_DISABLED-$POWERLEVEL9K_FOO_DISABLED}` is equal to `true`. Example: POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(dir) - By default `dir` is shown on the left and on the right. - `POWERLEVEL9K_DIR_LEFT_DISABLED=true` disables `dir` on the left. - `POWERLEVEL9K_DIR_RIGHT_DISABLED=true` disables `dir` on the right. - `POWERLEVEL9K_DIR_DISABLED=true` disables `dir` everywhere. Note that it's possible to hide segments without disabling their evaluation through expansions. For example: POWERLEVEL9K_DIR_CONTENT_EXPANSION='${HIDE_DIR-$P9K_CONTENT}' POWERLEVEL9K_DIR_VISUAL_IDENTIFIER_EXPANSION='${HIDE_DIR-$P9K_VISUAL_IDENTIFIER}' With these settings, `HIDE_DIR=''` hides `dir` while `unset HIDE_DIR` restores it. fixes #205 --- internal/p10k.zsh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index e28bf616..e409c36c 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3785,6 +3785,30 @@ _p9k_init_params() { # # These correspond to `java -fullversion` and `java -version` respectively. _p9k_declare -b POWERLEVEL9K_JAVA_VERSION_FULL 1 + + local -i i=1 + while (( i <= $#_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS )); do + local segment=${(U)_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[i]} + local var=POWERLEVEL9K_${segment}_LEFT_DISABLED + (( $+parameters[$var] )) || var=POWERLEVEL9K_${segment}_DISABLED + if [[ ${(P)var} == true ]]; then + _POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[i,i]=() + else + (( ++i )) + fi + done + + local -i i=1 + while (( i <= $#_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS )); do + local segment=${(U)_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[i]} + local var=POWERLEVEL9K_${segment}_RIGHT_DISABLED + (( $+parameters[$var] )) || var=POWERLEVEL9K_${segment}_DISABLED + if [[ ${(P)var} == true ]]; then + _POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[i,i]=() + else + (( ++i )) + fi + done } typeset -ga __p9k_wrapped_zle_widgets