#!/bin/sh state="$HOME/.battery_warned" if [ -f "$state" ]; then rm "$state" fi while true; do perc="$(acpi | awk 'BEGIN { IFS="," } /Battery 0: Discharging/ { print(substr($4,0,length($4)-2)) }')" if [ -n "$perc" ]; then if [[ "$perc" < "20" ]] && [[ ! -f "$state" ]]; then notify-send -u critical "Battery low! $perc%" touch "$state" fi fi sleep 60s done