From aec4c9c5934b335e3491bc72516d7d3e50ed5a83 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 5 Nov 2016 16:27:49 +0100 Subject: [PATCH] panel: add battery lemon --- os/arch/.config/panel/lemons/battery | 22 ++++++++++++++++++++++ os/arch/.config/panel/panel | 18 +++++++++++++++++- os/arch/.config/panel/panel-config | 12 ++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 os/arch/.config/panel/lemons/battery diff --git a/os/arch/.config/panel/lemons/battery b/os/arch/.config/panel/lemons/battery new file mode 100755 index 00000000..8e61dcc9 --- /dev/null +++ b/os/arch/.config/panel/lemons/battery @@ -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 diff --git a/os/arch/.config/panel/panel b/os/arch/.config/panel/panel index b559561c..bbd91231 100755 --- a/os/arch/.config/panel/panel +++ b/os/arch/.config/panel/panel @@ -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 } diff --git a/os/arch/.config/panel/panel-config b/os/arch/.config/panel/panel-config index 0bf1b79b..3e4a8b17 100644 --- a/os/arch/.config/panel/panel-config +++ b/os/arch/.config/panel/panel-config @@ -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=""