#!/bin/sh set -e export NOTIFY_SHORT=battery export NOTIFY_LONG=battery readonly TS_FILE="$XDG_DATA_HOME/battery-notification.timestamp" [ -f "$TS_FILE" ] || touch "$TS_FILE" cd /sys/class/power_supply/BAT1 read cap <capacity read status <status if [ $cap -le 20 -a $status != Charging ] then now=`date +%s` read was <"$TS_FILE" if (set +e; [ $(($now - ${was:-0} > 60)) -eq 1 ]) then notify 'Battery Low' \ 'The current battery level is below 20%. Plug the device into a charger ASAP' \ -u critical echo $now >"$TS_FILE" fi fi { printf 'percentage=%s%%\nicon=' $cap if [ $status = Charging ]; 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