Created
December 1, 2013 23:15
-
-
Save weatheredwatcher/7742126 to your computer and use it in GitHub Desktop.
I found this script on the i3 forums and thought that I'd share it from here. It's a cool little script that checks for battery strength and warns you via the nagbar if your battery is running low. Helpful if you run the i3 status bar on the bottom and don't always notice if the battery is low!!
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 | |
SLEEP_TIME=5 # Default time between checks. | |
SAFE_PERCENT=30 # Still safe at this level. | |
DANGER_PERCENT=15 # Warn when battery at this level. | |
CRITICAL_PERCENT=5 # Hibernate when battery at this level. | |
NAGBAR_PID=0 | |
export DISPLAY=:0.0 | |
function launchNagBar | |
{ | |
i3-nagbar -m 'Battery low!' -b 'Hibernate!' 'pm-hibernate' >/dev/null 2>&1 & | |
NAGBAR_PID=$! | |
} | |
function killNagBar | |
{ | |
if [[ $NAGBAR_PID -ne 0 ]]; then | |
ps -p $NAGBAR_PID | grep "i3-nagbar" | |
if [[ $? -eq 0 ]]; then | |
kill $NAGBAR_PID | |
fi | |
NAGBAR_PID=0 | |
fi | |
} | |
while [ true ]; do | |
killNagBar | |
if [[ -n $(acpi -b | grep -i discharging) ]]; then | |
rem_bat=$(acpi -b | grep -Eo "[0-9]+%" | grep -Eo "[0-9]+") | |
if [[ $rem_bat -gt $SAFE_PERCENT ]]; then | |
SLEEP_TIME=10 | |
else | |
SLEEP_TIME=5 | |
if [[ $rem_bat -le $DANGER_PERCENT ]]; then | |
SLEEP_TIME=2 | |
launchNagBar | |
fi | |
if [[ $rem_bat -le $CRITICAL_PERCENT ]]; then | |
SLEEP_TIME=1 | |
pm-hibernate | |
fi | |
fi | |
else | |
SLEEP_TIME=10 | |
fi | |
sleep ${SLEEP_TIME}m | |
done | |
fi | |
fi | |
fi | |
done | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment