diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-03-19 00:50:45 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-03-19 00:50:45 -0400 |
commit | 5ebdac196f7f3a18ce7c53699153f1545869d87b (patch) | |
tree | 889757a2ea3c2e9e46c6a3db5d1ed0897c2ef1dd /bin | |
parent | cee1f02b0a18c7f755c5d82eaa8fca45f7310cbd (diff) | |
download | conf-5ebdac196f7f3a18ce7c53699153f1545869d87b.tar.gz conf-5ebdac196f7f3a18ce7c53699153f1545869d87b.zip |
support multiple batteries
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/fancy-prompt | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/bin/fancy-prompt b/bin/fancy-prompt index 148cb05..b99d1c3 100755 --- a/bin/fancy-prompt +++ b/bin/fancy-prompt @@ -1,4 +1,5 @@ #!/usr/bin/env perl +use 5.010; # keep these commented out in actual use, for speed (saves ~2ms) # use strict; # use warnings; @@ -178,13 +179,13 @@ print $prompt_escape eq 'zsh' ? "%{\n%}" : "\n"; print join(' ', $errstr, $promptstr, ''); sub battery { - my $now = slurp('/sys/class/power_supply/BAT0/charge_now'); - $now = slurp('/sys/class/power_supply/BAT0/energy_now') - if !defined($now); - my $full = slurp('/sys/class/power_supply/BAT0/charge_full'); - $full = slurp('/sys/class/power_supply/BAT0/energy_full') - if !defined($full); - return if !defined($full); + my $now = 0; + my $full = 0; + for my $battery (glob('/sys/class/power_supply/*')) { + $now += slurp("$battery/charge_now") // slurp("$battery/energy_now"); + $full += slurp("$battery/charge_full") // slurp("$battery/energy_full"); + } + return unless $full; return int(100 * $now / $full); } |