sway: sleep earlier on battery

This commit is contained in:
Konstantin Koslowski 2021-01-03 19:51:23 +01:00
parent 2e72543e96
commit a843390315
2 changed files with 46 additions and 1 deletions

39
bin/suspend Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
BAT_PATH=/sys/class/power_supply
BAT=BAT0
MODE=suspend-then-hibernate
# 0: charging
# 1: discharging/unknown
function _state() {
f=$BAT_PATH/$BAT/status
s=1
if [ -e $f ]; then
s=$(grep -c Discharging $f)
fi
echo $s
}
function _suspend() {
state=$(_state)
force=${1:-0}
echo "INFO: state: $state, force: $force"
if [ $state -eq 1 -o $force -eq 1 ]; then
systemctl $MODE
else
echo "ERROR: state: $state, force: $force"
fi
}
case $1 in
suspend)
_suspend 0
;;
force)
_suspend 1
;;
*)
echo "ERROR: invalid command: \"$1\""
echo "possible options: [suspend|force]"
;;
esac