From c1c4a087b67e905f24f0ffde59cae707352d906b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 15 Sep 2023 01:50:39 +0300 Subject: eww: Send a critical notification on low battery --- .config/eww/scripts/battery | 75 ++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to '.config') diff --git a/.config/eww/scripts/battery b/.config/eww/scripts/battery index 071f0e9..a1c551c 100755 --- a/.config/eww/scripts/battery +++ b/.config/eww/scripts/battery @@ -2,37 +2,50 @@ set -e +readonly TS_FILE="$XDG_DATA_HOME/battery-notification.timestamp" +[ -f "$TS_FILE" ] || touch "$TS_FILE" + cd /sys/class/power_supply/BAT1 -awk ' - FILENAME == "capacity" { - val = $0 - printf "percentage=%d%%\n", val - } +read cap 60)) -eq 1 ]) + then + notify-send -a 'battery' -u critical 'Battery Low' \ + 'The current battery level is below 20%. Plug the device into a charger ASAP.' + echo $now >"$TS_FILE" + fi +fi - FILENAME == "status" { - printf "icon=" - if ($0 == "Charging") - print "󰂄" - else if (val >= 90) - print "󰁹" - else if (val >= 80) - print "󰂂" - else if (val >= 70) - print "󰂁" - else if (val >= 60) - print "󰁿" - else if (val >= 50) - print "󰁾" - else if (val >= 40) - print "󰁽" - else if (val >= 30) - print "󰁼" - else if (val >= 20) - print "󰁻" - else if (val >= 10) - print "󰁺" - else - print "󰂎" - }' capacity status \ - | jo +{ + printf 'percentage=%s\nicon=' $cap + if [ $status = Charing ]; then + echo "󰂄" + elif [ $cap -ge 90 ]; then + echo "󰁹" + elif [ $cap -ge 80 ]; then + echo "󰂂" + elif [ $cap -ge 70 ]; then + echo "󰂁" + elif [ $cap -ge 60 ]; then + echo "󰁿" + elif [ $cap -ge 50 ]; then + echo "󰁾" + elif [ $cap -ge 40 ]; then + echo "󰁽" + elif [ $cap -ge 30 ]; then + echo "󰁼" + elif [ $cap -ge 20 ]; then + echo "󰁻" + elif [ $cap -ge 10 ]; then + echo "󰁺" + else + echo "󰂎" + fi +} | jo -- cgit v1.2.3