panel: add battery lemon

This commit is contained in:
Henrik Lissner 2016-11-05 16:27:49 +01:00
parent 145fbccbfb
commit aec4c9c593
3 changed files with 51 additions and 1 deletions

View file

@ -0,0 +1,22 @@
#!/usr/bin/env dash
# 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
BAT=$(acpi --battery)
PERC=$(echo $BAT | cut -d, -f2)
echo -n "B${PERC#?}:"
echo "$BAT" | grep charging >/dev/null && echo "1" || echo "0"
sleep 15
done

View file

@ -60,6 +60,22 @@ parse() {
data="${line#?}"
case $line in
# Minimal icons
B*) perc="${data%\%:*}"
state="${data#*:}"
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
[ "$state" = "1" ] && battery="${icon}${ICON_BATAC}" || battery="${icon} "
;;
U*) updates=" %{F${COLOR_DIM}}$ICON_UPD%{F-}"
if [ "$data" -gt 0 ]; then
updates=" %{F${COLOR_2}}$ICON_UPD$data%{F-}"
@ -187,7 +203,7 @@ parse() {
echo -e \
"%{l}${wm}${song}" \
"%{c}${xtitle}" \
"%{r}${mail}${updates}${vol}${wifi}${datetime} "
"%{r}${battery}${mail}${updates}${vol}${wifi}${datetime} "
done
}

View file

@ -68,3 +68,15 @@ ICON_SPEAKER=""
# misc
ICON_MAIL=""
ICON_UPD=""
# battery
ICON_BAT0=""
ICON_BAT1=""
ICON_BAT2=""
ICON_BAT3=""
ICON_BAT4=""
ICON_BAT5=""
ICON_BAT6=""
ICON_BAT7=""
ICON_BAT8=""
ICON_BAT9=""
ICON_BATAC=""