"pmset -g batt" parsing error on MacOS
aero opened this issue · 0 comments
aero commented
When 100% charged on MacOS.
$ pmset -g batt
Now drawing from 'AC Power'
-InternalBattery-0 (id=4718691) 100%; charged; 0:00 remaining present: true
$
$ eval `./angel-PS1`
angel installed.
Use of uninitialized value $1 in division (/) at ./angel-PS1 line 2183.
the following code can't parsing the result
return sub {
my $pmset_batt = `pmset -g batt`;
# 37%; AC attached; not charging
# 8%; charging; 2:46 remaining
# 9%; discharging; (no estimate)
# 7%; discharging; 0:13 remaining
$pmset_batt =~ m/\t([0-9]+)%;.* (dis)?charging/;
my $level = $1 / 100;
my $charging = ! defined $2;
return ($level, $charging);
}