Even better

This commit is contained in:
David Heinemeier Hansson
2026-03-02 14:15:46 +01:00
parent 758e9d442f
commit 5e516be544
3 changed files with 21 additions and 9 deletions
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
# Returns the battery full capacity in Wh (rounded to whole number).
# Used by omarchy-battery-status for displaying battery capacity.
battery_info=$(upower -i $(upower -e | grep BAT))
echo "$battery_info" | awk '/energy-full:/ {
printf "%d", $2
exit
}'
+7 -7
View File
@@ -5,12 +5,12 @@
battery_info=$(upower -i $(upower -e | grep BAT))
echo "$battery_info" | awk '/time to (empty|full)/ {
value = $4
unit = $5
gsub(/hours/, "h", unit)
gsub(/minutes/, "m", unit)
# Remove .0 from whole numbers
gsub(/\.0/, "", value)
print value unit
hours = int($4)
minutes = int(($4 - hours) * 60)
if (minutes > 0) {
printf "%dh %dm", hours, minutes
} else {
printf "%dh", hours
}
exit
}'
+3 -2
View File
@@ -19,9 +19,10 @@ power_rate=$(echo "$battery_info" | awk '/energy-rate/ {
state=$(echo "$battery_info" | awk '/state/ { print $2; exit }')
time_remaining=$(omarchy-battery-remaining-time)
capacity=$(omarchy-battery-capacity)
if [[ $state == "charging" ]]; then
echo "󰁹 Battery at ${percentage}% with ${time_remaining} left to full gaining ${power_rate}W"
echo "󰁹 Battery ${percentage}% · ${time_remaining} to full ·  ${power_rate}W / ${capacity}Wh"
else
echo "󰁹 Battery at ${percentage}% with ${time_remaining} left using ${power_rate}W"
echo "󰁹 Battery ${percentage}% · ${time_remaining} left ·  ${power_rate}W / ${capacity}Wh"
fi