Skip to content

Commit c2cd5c8

Browse files
hulkkmartinbeentjes
authored andcommitted
fix time to charge display on mac, closes #28 (#68)
* fix time to charge display on mac, closes #28 * add charging colour to battery_status_fg * fix incorrect colours when discharging * change charging colour default to green * add text to show charged when applicable instead of 0:00
1 parent 8d5adf9 commit c2cd5c8

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

scripts/battery_remain.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ battery_discharging() {
1515
[[ $status =~ (discharging) ]]
1616
}
1717

18+
battery_charged() {
19+
local status="$(battery_status)"
20+
[[ $status =~ (charged) ]]
21+
}
22+
1823
pmset_battery_remaining_time() {
1924
local status="$(pmset -g batt)"
2025
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
@@ -31,8 +36,16 @@ pmset_battery_remaining_time() {
3136
else
3237
echo $remaining_time | awk '{printf "- %s left", $1}'
3338
fi
39+
elif battery_charged; then
40+
if $short; then
41+
echo $remaining_time | awk '{printf "charged", $1}'
42+
else
43+
echo $remaining_time | awk '{printf "fully charged", $1}'
44+
fi
3445
else
35-
if !$short; then
46+
if $short; then
47+
echo $remaining_time | awk '{printf "~%s", $1}'
48+
else
3649
echo $remaining_time | awk '{printf "- %s till full", $1}'
3750
fi
3851
fi
@@ -76,9 +89,7 @@ main() {
7689
if battery_discharging; then
7790
print_battery_remain
7891
else
79-
if !$short; then
80-
print_battery_full
81-
fi
92+
print_battery_full
8293
fi
8394
}
8495
main

scripts/battery_status_fg.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@ color_full_charge_default="#[fg=green]"
88
color_high_charge_default="#[fg=yellow]"
99
color_medium_charge_default="#[fg=colour208]" # orange
1010
color_low_charge_default="#[fg=red]"
11+
color_charging_default="#[fg=green]"
1112

1213
color_full_charge=""
1314
color_high_charge=""
1415
color_medium_charge=""
1516
color_low_charge=""
17+
color_charging=""
1618

1719
get_charge_color_settings() {
1820
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
1921
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
2022
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
2123
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
24+
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
2225
}
2326

2427
print_battery_status_fg() {
2528
# Call `battery_percentage.sh`.
2629
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
27-
if [ $percentage -eq 100 ]; then
30+
status=$(battery_status | awk '{print $1;}')
31+
if [ $status == 'charging' ]; then
32+
printf $color_charging
33+
elif [ $percentage -eq 100 ]; then
2834
printf $color_full_charge
2935
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
3036
printf $color_high_charge

0 commit comments

Comments
 (0)