From 5e516be5447064352ea8188cba9f13508b04c3c0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 2 Mar 2026 14:15:46 +0100 Subject: [PATCH] Even better --- bin/omarchy-battery-capacity | 11 +++++++++++ bin/omarchy-battery-remaining-time | 14 +++++++------- bin/omarchy-battery-status | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100755 bin/omarchy-battery-capacity diff --git a/bin/omarchy-battery-capacity b/bin/omarchy-battery-capacity new file mode 100755 index 00000000..fa4b4c03 --- /dev/null +++ b/bin/omarchy-battery-capacity @@ -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 +}' diff --git a/bin/omarchy-battery-remaining-time b/bin/omarchy-battery-remaining-time index c54a3807..9c2c7019 100755 --- a/bin/omarchy-battery-remaining-time +++ b/bin/omarchy-battery-remaining-time @@ -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 }' diff --git a/bin/omarchy-battery-status b/bin/omarchy-battery-status index b1e54d8b..021c0aa4 100755 --- a/bin/omarchy-battery-status +++ b/bin/omarchy-battery-status @@ -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