Skip to content

Commit 9a4e6ef

Browse files
vass-davidmartinbeentjes
authored andcommitted
Show time to charge battery on Mac OS (#46)
* Show time to charge battery on Mac OS * Rename variable to
1 parent 49ff299 commit 9a4e6ef

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

scripts/battery_remain.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ battery_discharging() {
1010
}
1111

1212
pmset_battery_remaining_time() {
13-
pmset -g batt | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}'
13+
local status="$(pmset -g batt)"
14+
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
15+
echo '- Calculating estimate...'
16+
else
17+
local remaining_time="$(echo $status | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}')"
18+
if battery_discharging; then
19+
echo $remaining_time | awk '{printf "- %s left", $1}'
20+
else
21+
echo $remaining_time | awk '{printf "- %s till full", $1}'
22+
fi
23+
fi
1424
}
1525

1626
print_battery_remain() {
@@ -33,7 +43,9 @@ print_battery_remain() {
3343
}
3444

3545
print_battery_full() {
36-
if command_exists "upower"; then
46+
if command_exists "pmset"; then
47+
pmset_battery_remaining_time
48+
elif command_exists "upower"; then
3749
battery=$(upower -e | grep battery | head -1)
3850
upower -i $battery | grep 'time to full' | awk '{printf "- %s %s till full", $4, $5}'
3951
fi

0 commit comments

Comments
 (0)