helm/os/arch/.config/panel/lemons/battery

55 lines
1.2 KiB
Plaintext
Raw Normal View History

2016-11-05 08:27:49 -07:00
#!/usr/bin/env dash
2016-11-06 16:40:02 -08:00
. $(dirname $0)/../panel-config
2016-11-05 08:27:49 -07:00
# No guarantee that it will be called BAT0, but it suits my purposes.
if ! command -v acpi >/dev/null
then
>&2 echo "acpi is not installed, battery segment disabled"
exit
fi
if [ ! -d "/sys/class/power_supply/BAT0" ]
then
>&2 echo "No battery! This must be a PC"
exit
fi
2016-11-06 16:40:02 -08:00
ICON_BAT0=""
ICON_BAT1=""
ICON_BAT2=""
ICON_BAT3=""
ICON_BAT4=""
ICON_BAT5=""
ICON_BAT6=""
ICON_BAT7=""
ICON_BAT8=""
ICON_BAT9=""
ICON_BATAC=""
2016-11-05 08:27:49 -07:00
while :
do
BAT=$(acpi --battery)
PERC=$(echo $BAT | cut -d, -f2)
2016-11-06 16:40:02 -08:00
case "${PERC#??}" in
100|9[0-9]) icon="${ICON_BAT9}" ;;
8[0-9]) icon="${ICON_BAT8}" ;;
7[0-9]) icon="${ICON_BAT7}" ;;
6[0-9]) icon="${ICON_BAT6}" ;;
5[0-9]) icon="${ICON_BAT5}" ;;
4[0-9]) icon="${ICON_BAT4}" ;;
3[0-9]) icon="%{F$COLOR_3}${ICON_BAT3}%{F-}" ;;
2[0-9]) icon="%{F$COLOR_3}${ICON_BAT2}%{F-}" ;;
1[0-9]) icon="%{F$COLOR_1}${ICON_BAT1}%{F-}" ;;
*) icon="%{F$COLOR_1}${ICON_BAT0}%{F-}" ;;
esac
if echo "$BAT" | grep charging >/dev/null
then
echo "${icon}${ICON_BATAC}"
else
echo "${icon} "
fi
2016-11-05 08:27:49 -07:00
sleep 15
done