helm/os/+arch/.config/panel/lemons/battery
2017-04-25 23:29:43 -04:00

38 lines
1,023 B
Bash
Executable file

#!/usr/bin/env dash
. $(dirname $0)/../panel-config
# 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
while :; do
data=$(acpi --battery)
perc=${${${data#*,}%,*}:1:-1}
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
echo -n "${icon}"
[ "${data/ charging/}" == "$data" ] && echo "${ICON_BATAC}"
sleep 15
done
# vim:set ft=sh: