Fix battery time showing hours instead of minutes (#5137)

When upower reported time in minutes, the value was incorrectly
passed through the hours conversion path, displaying e.g. "25h"
instead of "25m".
This commit is contained in:
Federico Sapuppo
2026-04-01 18:00:58 +02:00
committed by GitHub
parent 7c13bd5801
commit e0fed4a9f7
+7 -10
View File
@@ -7,19 +7,16 @@ battery_info=$(upower -i $(upower -e | grep BAT))
echo "$battery_info" | awk '/time to (empty|full)/ {
value = $4
unit = $5
if (unit == "minutes") {
hours = int(value / 60)
minutes = int(value % 60)
if (unit ~ /^minute/) {
printf "%dm", int(value)
} else {
hours = int(value)
minutes = int((value - hours) * 60)
}
if (hours > 0 && minutes > 0) {
printf "%dh %dm", hours, minutes
} else if (hours > 0) {
printf "%dh", hours
} else {
printf "%dm", minutes
if (minutes > 0) {
printf "%dh %dm", hours, minutes
} else {
printf "%dh", hours
}
}
exit
}'