Mike S 940b8ed192
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.
2021-02-15 18:13:29 +03:00

46 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Prints all batteries, their percentage remaining and an emoji corresponding
# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
case $BLOCK_BUTTON in
3) notify-send "🔋 Battery module" "🔋: discharging
🛑: not charging
♻: stagnant charge
🔌: charging
⚡: charged
❗: battery very low!
- Scroll to change adjust xbacklight." ;;
4) xbacklight -inc 10 ;;
5) xbacklight -dec 10 ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
# Check if battery directories are detected
[ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1
# Loop through all attached batteries and format the info
STATUS=""
for battery in /sys/class/power_supply/BAT?*
do
# Sets up the status and capacity
status=$(cat "$battery/status")
case "$status" in
"Full") status="⚡" ;;
"Discharging") status="🔋" ;;
"Charging") status="🔌" ;;
"Not charging") status="🛑" ;;
"Unknown") status="🔋❓" ;;
esac
capacity=$(cat "$battery/capacity")
# Will make a warn variable if discharging and low
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
# Prints the info
TEMP=""
printf -v TEMP "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
STATUS="$STATUS $TEMP"
done
echo "$STATUS"
return 0