Fix battery i3block

This commit is contained in:
2022-12-15 13:25:38 -05:00
parent be2e73fda6
commit e2a9e753ff
6 changed files with 18 additions and 10 deletions

View File

@@ -24,12 +24,16 @@ my $short_text;
my $bat_number = $ENV{BLOCK_INSTANCE} || 0;
# read the first line of the "acpi" command output
open (ACPI, "acpi -b | grep 'Battery $bat_number' |") or die;
open (ACPI, "acpi -b 2>/dev/null| grep 'Battery $bat_number' |") or die;
$acpi = <ACPI>;
close(ACPI);
# fail on unexpected output
if ($acpi !~ /: (\w+), (\d+)%/) {
if (not defined($acpi)) {
# don't print anything to stderr if there is no battery
exit(0);
}
elsif ($acpi !~ /: ([\w\s]+), (\d+)%/) {
die "$acpi\n";
}