mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
Add support for multiple batteries
Hello, I have a laptop with two batteries and I want to display them both. Your script has support for 2 batteries in theory, i.e. it prints two strings with status. But only the first result is used. I propose concatenating two results in one string and echoing *it* instead. That way 2 batteries are displayed inside one dwm block.
This commit is contained in:
parent
8f36b8feb8
commit
940b8ed192
@ -20,6 +20,8 @@ esac
|
|||||||
[ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1
|
[ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1
|
||||||
|
|
||||||
# Loop through all attached batteries and format the info
|
# Loop through all attached batteries and format the info
|
||||||
|
|
||||||
|
STATUS=""
|
||||||
for battery in /sys/class/power_supply/BAT?*
|
for battery in /sys/class/power_supply/BAT?*
|
||||||
do
|
do
|
||||||
# Sets up the status and capacity
|
# Sets up the status and capacity
|
||||||
@ -29,11 +31,15 @@ do
|
|||||||
"Discharging") status="🔋" ;;
|
"Discharging") status="🔋" ;;
|
||||||
"Charging") status="🔌" ;;
|
"Charging") status="🔌" ;;
|
||||||
"Not charging") status="🛑" ;;
|
"Not charging") status="🛑" ;;
|
||||||
"Unknown") status="♻️" ;;
|
"Unknown") status="🔋❓" ;;
|
||||||
esac
|
esac
|
||||||
capacity=$(cat "$battery/capacity")
|
capacity=$(cat "$battery/capacity")
|
||||||
# Will make a warn variable if discharging and low
|
# Will make a warn variable if discharging and low
|
||||||
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
|
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
|
||||||
# Prints the info
|
# Prints the info
|
||||||
printf "%s%s%d%%\n" "$status" "$warn" "$capacity"; unset warn
|
TEMP=""
|
||||||
done && return 0
|
printf -v TEMP "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
|
||||||
|
STATUS="$STATUS $TEMP"
|
||||||
|
done
|
||||||
|
echo "$STATUS"
|
||||||
|
return 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user