voidrice/.scripts/statusbar/i3battery

23 lines
659 B
Text
Raw Normal View History

#!/bin/sh
2018-07-16 23:16:47 +00:00
# Give a battery name (e.g. BAT0) as an argument.
capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit
status=$(cat /sys/class/power_supply/"$1"/status)
if [ "$capacity" -ge 80 ]; then
2018-07-16 23:16:47 +00:00
color="#00FF00"
elif [ "$capacity" -ge 60 ]; then
2018-07-17 18:45:12 +00:00
color="#FFFFFF"
elif [ "$capacity" -ge 40 ]; then
2018-07-16 23:16:47 +00:00
color="#FFF600"
elif [ "$capacity" -ge 20 ]; then
2018-07-16 23:16:47 +00:00
color="#FFAE00"
else
color="#FF0000"
fi
[ "$status" = "Charging" ] && color="#FFF"
printf "<span color='%s'>%s %s</span>" "$color" "$(echo "$status" | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$(echo "$capacity" | sed -e 's/$/%/')"