diff --git a/bin/omarchy-battery-remaining-time b/bin/omarchy-battery-remaining-time new file mode 100755 index 00000000..c54a3807 --- /dev/null +++ b/bin/omarchy-battery-remaining-time @@ -0,0 +1,16 @@ +#!/bin/bash + +# Returns the battery time remaining (to empty or full) in a compact format. + +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 + exit +}' diff --git a/bin/omarchy-battery-status b/bin/omarchy-battery-status new file mode 100755 index 00000000..b1e54d8b --- /dev/null +++ b/bin/omarchy-battery-status @@ -0,0 +1,27 @@ +#!/bin/bash + +# Returns a formatted battery status string with percentage and power draw/charge. +# Used by the battery notification hotkey (Ctrl + Shift + Super + B). + +battery_info=$(upower -i $(upower -e | grep BAT)) + +percentage=$(echo "$battery_info" | awk '/percentage/ { + print int($2) + exit +}') + +power_rate=$(echo "$battery_info" | awk '/energy-rate/ { + rounded = sprintf("%.1f", $2) + sub(/\.0$/, "", rounded) + print rounded + exit +}') + +state=$(echo "$battery_info" | awk '/state/ { print $2; exit }') +time_remaining=$(omarchy-battery-remaining-time) + +if [[ $state == "charging" ]]; then + echo "󰁹 Battery at ${percentage}% with ${time_remaining} left to full gaining ${power_rate}W" +else + echo "󰁹 Battery at ${percentage}% with ${time_remaining} left using ${power_rate}W" +fi diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index bd3ca4ab..9e0204b0 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -43,7 +43,7 @@ bindd = SUPER CTRL, S, Share, exec, omarchy-menu share # Waybar-less information bindd = SUPER CTRL ALT, T, Show time, exec, notify-send " $(date +"%A %H:%M — %d %B W%V %Y")" -bindd = SUPER CTRL ALT, B, Show battery remaining, exec, notify-send "󰁹 Battery is at $(omarchy-battery-remaining)%" +bindd = SUPER CTRL ALT, B, Show battery remaining, exec, notify-send "$(omarchy-battery-status)" # Control panels bindd = SUPER CTRL, A, Audio controls, exec, omarchy-launch-audio