dwmbar/modules/battery

45 lines
1.5 KiB
Text
Raw Normal View History

2019-10-21 18:53:57 +00:00
#!/bin/bash
2019-10-21 19:09:02 +00:00
# Prints out battery percentage
CHARGING_ICON=''
WARNING_ICON=''
BATTERY_FULL_ICON=''
BATTERY_2_ICON=''
BATTERY_3_ICON=''
BATTERY_4_ICON=''
2019-10-21 18:53:57 +00:00
get_battery()
{
if [ -d /sys/class/power_supply/BAT? ]; then
ac_adapter=$(cat /sys/class/power_supply/BAT?/status)
if [ "$ac_adapter" == "Charging" ]; then
2019-10-21 19:09:02 +00:00
echo "$CHARGING_ICON"
2019-10-21 18:53:57 +00:00
fi
# Will show all batteries with approximate icon for remaining power.
for x in /sys/class/power_supply/BAT?/capacity;
do
case "$(cat $x)" in
2019-10-21 19:09:02 +00:00
100) echo "$BATTERY_FULL_ICON" ;;
9[0-9]) echo "$BATTERY_FULL_ICON $(cat $x)%" ;;
8[0-9]|7[0-9]) echo "$BATTERY_2_ICON $(cat $x)%" ;;
6[0-9]|5[0-9]) echo "$BATTERY_3_ICON $(cat $x)%" ;;
4[0-9]|3[0-9]) echo "$BATTERY_4_ICON $(cat $x)%" ;;
2019-10-21 18:53:57 +00:00
2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then
2019-10-21 19:09:02 +00:00
echo "$BATTERY_4_ICON $(cat $x)%"
2019-10-21 18:53:57 +00:00
else
2019-10-21 19:09:02 +00:00
echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
2019-10-21 18:53:57 +00:00
fi ;;
[0-9]) if [ "$ac_adapter" == "Charging" ]; then
2019-10-21 19:09:02 +00:00
echo "$BATTERY_4_ICON $(cat $x)%"
2019-10-21 18:53:57 +00:00
else
2019-10-21 19:09:02 +00:00
echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
2019-10-21 18:53:57 +00:00
fi ;;
esac
done
fi
}
get_battery