diff --git a/README.md b/README.md index 5bf4775..4d5a080 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index eb56e0e..d31c90a 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -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