b8b87629157b30fc00d0b4af62dd0cf422896346

Author
Bruce Weirdan <weirdan@gmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Report only active battery (#4726)

On a system with multiple batteries (like thinkpads) report percentage
and time remaining only for the active battery (the one being
discharged).

Ideally we should report all batteries, but acpi only shows time remaining
for the active battery. Also callers of these functions expect a single
return value. This is still better than reporting 596% remaining (like it
did on my laptop).

For the reference, the output of acpi command with multiple batteries looks
like this:

    Battery 0: Unknown, 5%
    Battery 1: Discharging, 86%, 03:14:04 remaining

Diff

 1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
 2index 7c5bf6f82576b37f8b68d01dced300d3cd5f8a3b..d1adcd0b670f72ead54a5252c29e8c9e7ff927b1 100644
 3--- a/plugins/battery/battery.plugin.zsh
 4+++ b/plugins/battery/battery.plugin.zsh
 5@@ -117,7 +117,7 @@ elif [[ "$OSTYPE" = linux*  ]]; then
 6 
 7   function battery_pct() {
 8     if (( $+commands[acpi] )); then
 9-      acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]'
10+      acpi 2>/dev/null | command grep -E '^Battery.*(Disc|C)harging' | cut -f2 -d ',' | tr -cd '[:digit:]'
11     fi
12   }
13