Skip to content

Commit c02bc4c

Browse files
authored
make battery detection dynamic and improve icon support (#830)
- Dynamically detect any BAT* (BAT0, BAT1, etc.) instead of hardcoding BAT0 - Support systems with non-standard battery numbering - Expand charging icons to 11 levels
1 parent 7f76e55 commit c02bc4c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

β€ŽConfigs/.local/lib/hyde/battery.shβ€Ž

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ fi
2525
total_capacity=0
2626
battery_count=0
2727

28+
# Find the first available battery
29+
battery_path=""
30+
for bat in /sys/class/power_supply/BAT*; do
31+
if [[ -d "$bat" ]]; then
32+
battery_path="$bat"
33+
break
34+
fi
35+
done
36+
2837
for capacity in /sys/class/power_supply/BAT*/capacity; do
2938
if [[ -f "$capacity" ]]; then
3039
total_capacity=$((total_capacity + $(<"$capacity")))
@@ -42,11 +51,12 @@ average_capacity=$((total_capacity / battery_count))
4251
index=$((average_capacity / 10))
4352

4453
# Define icons for charging, discharging, and status
45-
charging_icons=("ο–„ " "ο–… " "ο–† " "ο–‡ " "ο–ˆ " "ο–‰ " "ο–Š ")
54+
# Charging icons from 0% to 100% (last icons repeated to fill 11 levels)
55+
charging_icons=("ο–… " "ο–† " "ο–‡ " "ο–ˆ " "ο–‰ " "ο–Š " "ο–Š " "ο–Š " "ο–Š " "ο–Š " "ο–„ ")
4656
discharging_icons=("σ°‚Ž" "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "σ°‚€" "󰂁" "σ°‚‚" "󰁹")
4757
status_icons=("" "X" "󰂇") # Add appropriate icons for different statuses
4858

49-
battery_status=$(cat /sys/class/power_supply/BAT0/status)
59+
battery_status=$(cat "$battery_path/status")
5060

5161
# Parse format options
5262
formats=("$@")

0 commit comments

Comments
Β (0)