voidrice/.local/bin/statusbar/battery

33 lines
923 B
Text
Raw Normal View History

#!/bin/sh
# Give a battery name (e.g. BAT0) as an argument.
2018-11-12 02:32:51 +00:00
case $BLOCK_BUTTON in
2019-04-02 23:20:26 +00:00
3) pgrep -x dunst >/dev/null && notify-send "🔋 Battery module" "🔋: discharging
🛑: not charging
2018-11-12 02:32:51 +00:00
♻: stagnant charge
🔌: charging
⚡: charged
2018-11-27 18:56:32 +00:00
❗: battery very low!
2018-11-12 02:32:51 +00:00
- Text color reflects charge left" ;;
esac
capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit
status=$(cat /sys/class/power_supply/"$1"/status)
if [ "$capacity" -ge 75 ]; then
2019-02-20 20:28:15 +00:00
color="#00ff00"
elif [ "$capacity" -ge 50 ]; then
2019-02-20 20:28:15 +00:00
color="#ffffff"
elif [ "$capacity" -ge 25 ]; then
2019-02-20 20:28:15 +00:00
color="#ffff00"
2018-07-16 23:16:47 +00:00
else
2019-02-20 20:28:15 +00:00
color="#ff0000"
2018-11-27 18:56:32 +00:00
warn="❗"
2018-07-16 23:16:47 +00:00
fi
2018-11-27 18:56:32 +00:00
[ -z $warn ] && warn=" "
2019-02-20 20:28:15 +00:00
[ "$status" = "Charging" ] && color="#ffffff"
printf "<span color='%s'>%s%s%s</span>" "$color" "$(echo "$status" | sed -e "s/,//;s/Discharging/🔋/;s/Not Charging/🛑/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$warn" "$(echo "$capacity" | sed -e 's/$/%/')"