battery (882B)
1 #!/bin/sh 2 3 # Prints all batteries, their percentage remaining and an emoji corresponding 4 # to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.). 5 6 case $BLOCK_BUTTON in 7 3) notify-send "🔋 Battery module" "🔋: discharging 8 🛑: not charging 9 ♻: stagnant charge 10 🔌: charging 11 ⚡: charged 12 ❗: battery very low!" ;; 13 esac 14 15 # Loop through all attached batteries. 16 for battery in /sys/class/power_supply/BAT? 17 do 18 # Get its remaining capacity and charge status. 19 capacity=$(cat "$battery"/capacity) || break 20 status=$(sed "s/Discharging/🔋/;s/Not charging/🛑/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/" "$battery"/status) 21 22 # If it is discharging and 25% or less, we will add a ❗ as a warning. 23 [ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗" 24 25 printf "%s%s%s%% " "$status" "$warn" "$capacity" 26 unset warn 27 done | sed s/\ $/\\n/