Fix time to full/empty when there are only minutes left
This commit is contained in:
@@ -5,12 +5,21 @@
|
|||||||
battery_info=$(upower -i $(upower -e | grep BAT))
|
battery_info=$(upower -i $(upower -e | grep BAT))
|
||||||
|
|
||||||
echo "$battery_info" | awk '/time to (empty|full)/ {
|
echo "$battery_info" | awk '/time to (empty|full)/ {
|
||||||
hours = int($4)
|
value = $4
|
||||||
minutes = int(($4 - hours) * 60)
|
unit = $5
|
||||||
if (minutes > 0) {
|
if (unit == "minutes") {
|
||||||
printf "%dh %dm", hours, minutes
|
hours = int(value / 60)
|
||||||
|
minutes = int(value % 60)
|
||||||
} else {
|
} 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
|
printf "%dh", hours
|
||||||
|
} else {
|
||||||
|
printf "%dm", minutes
|
||||||
}
|
}
|
||||||
exit
|
exit
|
||||||
}'
|
}'
|
||||||
|
|||||||
Reference in New Issue
Block a user