diff options
Diffstat (limited to 'dot_local/bin/executable_on-battery-suspend')
| -rw-r--r-- | dot_local/bin/executable_on-battery-suspend | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/dot_local/bin/executable_on-battery-suspend b/dot_local/bin/executable_on-battery-suspend new file mode 100644 index 0000000..2f39cc7 --- /dev/null +++ b/dot_local/bin/executable_on-battery-suspend @@ -0,0 +1,18 @@ +#!/bin/sh +# 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 |
