Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

add new option "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" #830

Merged
merged 4 commits into from Jun 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 21 additions & 17 deletions powerlevel9k.zsh-theme
Expand Up @@ -487,16 +487,20 @@ prompt_battery() {
[[ "${(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"
# return if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and the battery percentage is greater or equal
if [[ -v "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" && "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then
return
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
}

################################################################
Expand Down Expand Up @@ -637,14 +641,14 @@ prompt_user() {
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "ROOT_ICON"
)
elif sudo -n true 2>/dev/null; then
user_state=(
"STATE" "SUDO"
"CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "SUDO_ICON"
)
elif sudo -n true 2>/dev/null; then
user_state=(
"STATE" "SUDO"
"CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "SUDO_ICON"
)
else
user_state=(
"STATE" "DEFAULT"
Expand Down