diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 19da5bc9..2d664911 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -468,9 +468,24 @@ prompt_battery() { message="$bat_percent%%" fi - # Draw the prompt_segment - if [[ -n $bat_percent ]]; then - "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' + # override default icon if we are using battery stages + if [[ -n "$POWERLEVEL9K_BATTERY_STAGES" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_STAGES} - 1 ) )) + if [[ $segment > 1 ]]; then + local offset=$(( ($bat_percent / $segment) + 1 )) + # check if the stages are in an array or a string + [[ "${(t)POWERLEVEL9K_BATTERY_STAGES}" =~ "array" ]] && POWERLEVEL9K_BATTERY_ICON="$POWERLEVEL9K_BATTERY_STAGES[$offset]" || POWERLEVEL9K_BATTERY_ICON=${POWERLEVEL9K_BATTERY_STAGES:$offset:1} + fi + fi + + # override the default color if we are using a color level array + if [[ -n "$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND" ]] && [[ "${(t)POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND}" =~ "array" ]]; then + local segment=$(( 100.0 / (${#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND} - 1 ) )) + local offset=$(( ($bat_percent / $segment) + 1 )) + "$1_prompt_segment" "$0_${current_state}" "$2" "${POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[$offset]}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" + else + # Draw the prompt_segment + "$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" fi } @@ -1295,7 +1310,7 @@ powerlevel9k_prepare_prompts() { _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) # Reset start time - _P9K_TIMER_START=0xFFFFFFFF + _P9K_TIMER_START=0x7FFFFFFF if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then PROMPT='$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) @@ -1328,12 +1343,12 @@ NEWLINE=' } prompt_powerlevel9k_setup() { - # I decided to use the value below for better supporting 32-bit CPUs, since the previous value "99999999999" was causing issues on my Android phone, which is powered by an armv7l - # We don't have to change that until 19 January of 2038! :) + # The value below was set to better support 32-bit CPUs. + # It's the maximum _signed_ integer value on 32-bit CPUs. + # Please don't change it until 19 January of 2038. ;) # Disable false display of command execution time - # Maximum integer on 32-bit CPUs - _P9K_TIMER_START=2147483647 + _P9K_TIMER_START=0x7FFFFFFF # The prompt function will set these prompt_* options after the setup function # returns. We need prompt_subst so we can safely run commands in the prompt |