diff options
author | romkatv <roman.perepelitsa@gmail.com> | 2019-06-15 17:10:51 +0300 |
---|---|---|
committer | romkatv <roman.perepelitsa@gmail.com> | 2019-06-15 17:10:51 +0300 |
commit | d80d3a57042f8c69247348b1edd2d13d7a0ca25e (patch) | |
tree | 9cf2bc9bfadcfd5f229b106925766fcd4a01f839 /internal/p10k.zsh | |
parent | f95a0fc3eef9a33c1a783359ea17b9486b27e30e (diff) |
bug fix: don't assume that $#POWERLEVEL9K_BATTERY_STAGES == $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND
Reported in: https://github.com/romkatv/powerlevel10k/issues/88
Diffstat (limited to 'internal/p10k.zsh')
-rwxr-xr-x | internal/p10k.zsh | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 8a82583d..c92233b0 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -413,13 +413,6 @@ set_default -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND set_default POWERLEVEL9K_BATTERY_VERBOSE true typeset -g POWERLEVEL9K_BATTERY_STAGES -typeset -gA _P9K_BATTERY_STATES=( - 'low' 'red' - 'charging' 'yellow' - 'charged' 'green' - 'disconnected' "$DEFAULT_COLOR_INVERTED" -) - function _p9k_read_file() { _P9K_RETVAL='' [[ -n $1 ]] && read -r _P9K_RETVAL <$1 @@ -507,15 +500,19 @@ prompt_battery() { local msg="$bat_percent%%" [[ $POWERLEVEL9K_BATTERY_VERBOSE == true && -n $remain ]] && msg+=" ($remain)" - local icon=BATTERY_ICON bg=$DEFAULT_COLOR - if (( $#POWERLEVEL9K_BATTERY_STAGES || $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then + local icon=BATTERY_ICON + if (( $#POWERLEVEL9K_BATTERY_STAGES )); then local -i idx=$#POWERLEVEL9K_BATTERY_STAGES (( bat_percent < 100 )) && idx=$((bat_percent * $#POWERLEVEL9K_BATTERY_STAGES / 100 + 1)) - if (( $#POWERLEVEL9K_BATTERY_STAGES )); then - icon+=_$idx - typeset -g POWERLEVEL9K_$icon=$POWERLEVEL9K_BATTERY_STAGES[idx] - fi - (( $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )) && bg=$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[idx] + icon+=_$idx + typeset -g POWERLEVEL9K_$icon=$POWERLEVEL9K_BATTERY_STAGES[idx] + fi + + local bg=$DEFAULT_COLOR + if (( $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then + local -i idx=$#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND + (( bat_percent < 100 )) && idx=$((bat_percent * $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND / 100 + 1)) + bg=$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[idx] fi $1_prompt_segment $0_$state $2 "$bg" "$_P9K_BATTERY_STATES[$state]" $icon 0 '' $msg @@ -2486,6 +2483,13 @@ _p9k_init() { DEFAULT_COLOR_INVERTED=white fi + typeset -gA _P9K_BATTERY_STATES=( + 'low' 'red' + 'charging' 'yellow' + 'charged' 'green' + 'disconnected' "$DEFAULT_COLOR_INVERTED" + ) + local i for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i] |