commit cc127ae861addc9f1ac476d764fb682605b77409 parent 05152fd0a5a85ee0f898be88e46d7d1bc9e88ee0 Author: clamiax <smoppy@gmail.com> Date: Tue, 8 Oct 2013 23:01:49 +0200 If power cable is plugged in, just exit. Diffstat:
M | acpi | | | 17 | +++++++++++++++-- |
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/acpi b/acpi @@ -1,10 +1,20 @@ #!/bin/bash -SUSPEND_TO=mem +STATE=mem BATTCRITIC=2 +BATTWARNING=5 +ACDEVFILE=/sys/devices/pci0000:00/firmware_node/ACPI0003:00/power_supply/AC0/online + +acplugged() { + cat "$ACDEVFILE" +} + +warning() { + xmessage -center "WARNING: battery level is ${t}%" +} suspend() { - echo -n $SUSPEND_TO > /sys/power/state + echo -n $STATE > /sys/power/state } getbattery() { @@ -17,8 +27,11 @@ getbattery() { } main() { + [ $(acplugged) -eq 1 ] && exit t=$(getbattery) + [ $t -lt $BATTCRITIC ] && suspend + [ $t -lt $BATTWARNING ] && warning $t } main "$@"