-
Notifications
You must be signed in to change notification settings - Fork 98
Add option to hide the battery percentage if above user-defined threshold #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,25 @@ print_battery_percentage() { | |||||
| } | ||||||
|
|
||||||
| main() { | ||||||
| print_battery_percentage | ||||||
| local bat_pct | ||||||
| local bat_pct_raw | ||||||
|
|
||||||
| bat_pct_raw="$(print_battery_percentage)" | ||||||
| bat_pct="${bat_pct_raw//%/}" | ||||||
|
|
||||||
| if ! [[ "$bat_pct" =~ ^[0-9]+$ ]] | ||||||
| then | ||||||
| # Display bat percentage string if not a number | ||||||
| echo -n "$bat_pct_raw" | ||||||
| return | ||||||
| fi | ||||||
|
|
||||||
| local hide_if_above | ||||||
| hide_if_above="$(get_tmux_option "@batt_percentage_hide_if_above")" | ||||||
|
|
||||||
| if [[ "$bat_pct" -lt "${hide_if_above}" ]] | ||||||
|
||||||
| if [[ "$bat_pct" -lt "${hide_if_above}" ]] | |
| if [[ -n "$hide_if_above" && "$hide_if_above" =~ ^[0-9]+$ && "$bat_pct" -lt "$hide_if_above" ]] |
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.
The comparison operator creates an off-by-one boundary issue. The PR description states the feature should hide the percentage if battery level is ">" (greater than) the threshold, using the example "> 90". However, using -lt here means the percentage is displayed when battery is strictly less than the threshold, which means it's hidden when battery is greater than OR EQUAL to the threshold.
For a threshold of 90:
To match the description, change the comparison to use -le (less than or equal to) instead of -lt.