Last active
July 21, 2022 02:59
-
-
Save sach1t/a32f62bbd2493c23459970c240503f00 to your computer and use it in GitHub Desktop.
Sway battery low notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bat_low_threshold=$1 | |
poll_interval=60 # seconds | |
function bat_high { | |
local cap=$(cat /sys/class/power_supply/BAT0/capacity) | |
if [[ $cap -lt $bat_low_threshold ]]; then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
function nap { | |
sleep $poll_interval | |
} | |
for pid in $(pidof -x "batman.sh"); do | |
if [ $pid != $$ ]; then | |
echo "Batman #$pid is already on patrol!" | |
exit 1 | |
fi | |
done | |
while true; do | |
while bat_high; do nap; done | |
swaynag --message "Battery is low" | |
until bat_high; do nap; done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment