X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=X%2F.local%2Fbin%2Fbat_mgt.sh;fp=X%2F.local%2Fbin%2Fbat_mgt.sh;h=cfdbdd0dcf3b4375b1507306a4b8faa83bd3a5df;hb=ac24a79f863f3d876d9e84a789d32c64d989c20d;hp=0000000000000000000000000000000000000000;hpb=d23bda261ed2f98974d5e9b1539d24e73bdd6a7a;p=max%2Fdotfiles.git diff --git a/X/.local/bin/bat_mgt.sh b/X/.local/bin/bat_mgt.sh new file mode 100755 index 0000000..cfdbdd0 --- /dev/null +++ b/X/.local/bin/bat_mgt.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Polls the battery status once per minute. Echos the status to ratpoison if the +# battery is discharging. At low battery status, it warns at 30,20 and 15 minutes +# remaining. Shutsdown at 9 minutes remaining. Requires 'acpitool' to poll the battery. + +while [ 1 ]; do + if [ $(acpitool | awk '/AC adapter/{print $4}') = "off-line" ]; then + bat_stat="$(acpitool | grep Battery)" + seconds_remaining=$(echo $bat_stat | awk '{print $6}' | awk -F':' '{print $1*3600 + $2*60 + $3}') + if [ $seconds_remaining -le 840 ]; then + sudo shutdown -h now + elif [ $seconds_remaining -le 900 ]; then + ratpoison -c "echo Critical! 15 minutes of battery remaining. Shutting down in 1minute." + elif [ $seconds_remaining -le 1200 ]; then + ratpoison -c "echo Warning! 20 minutes of battery remaining. Shuttind down in 5 minutes." + elif [ $seconds_remaining -le 1800 ]; then + ratpoison -c "echo Warning, 30 minutes of battery remaining. Shutting down in 15 minutes." + fi + ratpoison -c "echo $bat_stat" + fi + sleep 60 +done +