From b135f8bf4145a86d1d1186b582fc9ea41dd13b50 Mon Sep 17 00:00:00 2001 From: Julian <167174811+JBTastic@users.noreply.github.com> Date: Fri, 11 Jul 2025 02:17:18 +0200 Subject: [PATCH] Fix battery detection on systems with multiple ACPI batteries by filtering phantom batteries with 0% --- scripts/battery_percentage.sh | 2 +- scripts/battery_remain.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index 7061ec4..17e10de 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -9,7 +9,7 @@ print_battery_percentage() { if command_exists "pmset"; then pmset -g batt | grep -o "[0-9]\{1,3\}%" elif command_exists "acpi"; then - acpi -b | grep -m 1 -Eo "[0-9]+%" + acpi -b | grep -v " 0%" | grep -m 1 -Eo "[0-9]+%" elif command_exists "upower"; then # use DisplayDevice if available otherwise battery local battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1) diff --git a/scripts/battery_remain.sh b/scripts/battery_remain.sh index f456b2f..881206b 100755 --- a/scripts/battery_remain.sh +++ b/scripts/battery_remain.sh @@ -110,9 +110,10 @@ acpi_battery_remaining_time() { if ! $short; then regex="$regex:[0-9]+" fi - acpi -b | grep -m 1 -Eo "$regex" + acpi -b | grep -v " 0%" | grep -m 1 -Eo "$regex" } + print_battery_remain() { if is_wsl; then echo "?" # currently unsupported on WSL