summaryrefslogtreecommitdiffstats
path: root/.i3/conky-wrapper.pl
diff options
context:
space:
mode:
Diffstat (limited to '.i3/conky-wrapper.pl')
-rwxr-xr-x.i3/conky-wrapper.pl44
1 files changed, 27 insertions, 17 deletions
diff --git a/.i3/conky-wrapper.pl b/.i3/conky-wrapper.pl
index 687762b..2e69d29 100755
--- a/.i3/conky-wrapper.pl
+++ b/.i3/conky-wrapper.pl
@@ -65,12 +65,15 @@ LINE: while (<$conky>) {
}
- if (m/^COMMAND: (.*) (.*)$/) {
+ if (m/^COMMAND: ([^\s]*)(?: (.*)?)$/) {
my $command = $1;
my @args = split / /, $2;
die "Unknown command requested: $command" unless defined $commands{$command};
- $in_progress{full_text} = $commands{$command}->(@args);
- push @data, clone \%in_progress;
+ my $command_ret = $commands{$command}->(@args);
+ for my $text (@$command_ret) {
+ $in_progress{full_text} = $text;
+ push @data, clone \%in_progress;
+ }
undef %in_progress;
next;
}
@@ -80,20 +83,27 @@ LINE: while (<$conky>) {
sub get_bat_stats {
- my $bat = shift // "BAT0";
-
- open my $fh, "<", "/sys/class/power_supply/$bat/uevent";
- my %values;
- while (my $line = <$fh>) {
- my ($key, $value) = split /=/, $line;
- $key =~ s/^POWER_SUPPLY_//;
- chomp $value;
- $values{$key} = $value;
- }
- close $fh;
+ my $bats = [@_] // ["BAT0"];
+
+ my $ret = [];
- my $time_remaining_hours = 0;
- $time_remaining_hours = $values{ENERGY_NOW} / $values{POWER_NOW} unless $values{POWER_NOW} == 0;
+ for my $bat (@$bats) {
+ next unless -e "/sys/class/power_supply/$bat";
- return sprintf("%s %s%%, %.2fW, %.2fh", $bat, $values{CAPACITY}, $values{POWER_NOW} / 1e6, $time_remaining_hours);
+ open my $fh, "<", "/sys/class/power_supply/$bat/uevent";
+ my %values;
+ while (my $line = <$fh>) {
+ my ($key, $value) = split /=/, $line;
+ $key =~ s/^POWER_SUPPLY_//;
+ chomp $value;
+ $values{$key} = $value;
+ }
+ close $fh;
+
+ my $time_remaining_hours = 0;
+ $time_remaining_hours = $values{ENERGY_NOW} / $values{POWER_NOW} unless $values{POWER_NOW} == 0;
+
+ push @$ret, sprintf("%s %s%%, %.2fW, %.2fh", $bat, $values{CAPACITY}, $values{POWER_NOW} / 1e6, $time_remaining_hours);
+ }
+ return $ret;
}