blob: 93155d61bccd1bdb9d52b0172b412108d7f92e21 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#!/usr/bin/env dash
# Suspend the system, but only if running on battery. Used as the
# swayidle `timeout` action so idle suspends save battery without ever
# firing while the laptop is plugged in.
#
# Manual suspends (sway keybinds, `systemctl suspend` over SSH) bypass
# this script and always work -- explicit user intent wins.
set -eu
for ac in /sys/class/power_supply/AC*/online \
/sys/class/power_supply/ADP*/online; do
[ -r "$ac" ] || continue
if [ "$(cat "$ac")" = "1" ]; then
exit 0
fi
done
exec systemctl suspend
|