Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percen

- `@batt_remain_short`: 'true' / 'false' - This will shorten the time remaining (when charging or discharging) to `~H:MM`.

`#{battery_percentage}`

- `@batt_percentage_hide_if_above`: integer (`[0-100]`) - Hides the battery percentage indicator if the battery level is above this threshold.

### Defaults

#### Options

- `@batt_remain_short`: 'false'
- `@batt_percentage_hide_if_above`: '' (always display battery percentage)

#### Icons/Colors

Expand Down
21 changes: 20 additions & 1 deletion scripts/battery_percentage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" ]]
then
echo -n "$bat_pct_raw"
fi
}
main