add new option "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" #830
add new option "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" #830
Conversation
Hides the battery segment if percentage hits 100%
If you add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sambadevi for the PR. I left a word on how to get rid of the code duplication..
powerlevel9k.zsh-theme
Outdated
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" | ||
if [[ -v "POWERLEVEL9K_BATTERY_HIDE_FULL" && "$POWERLEVEL9K_BATTERY_HIDE_FULL" == true ]]; then | ||
if [[ "$bat_percent" != "100" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to inverse that condition and exit early?
Something like this:
if [[ "${POWERLEVEL9K_BATTERY_HIDE_FULL}" == "true" && "${bat_percent}" == 100 ]]; then
return
fi
That way we get rid of that indentations and the code duplication..
Btw. Something itches my head: I always try to What do you think? |
Thanks! I didn’t think about the code duplication. I will take a look at this later on and update the PR accordingly |
Variable now holds an integer, if your battery status is greater or equal to this integer the segment will be hidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better! Thx @sambadevi
powerlevel9k.zsh-theme
Outdated
# Draw the prompt_segment | ||
"$1_prompt_segment" "$0_${current_state}" "$2" "${DEFAULT_COLOR}" "${battery_states[$current_state]}" "${message}" "BATTERY_ICON" | ||
fi | ||
if [[ -v "POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD" && "${bat_percent}" -ge $POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment before that line? Something like:
"Check if POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD is set and is exceeded by bat_percent, early exit."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I’ll add the comment
Hides the battery segment if percentage hits 100%