From 263f39704ae5e8f44a79d64dce2be048009b4df6 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Fri, 29 May 2026 11:18:13 +0100 Subject: feat(zsh): inhibit suspend while an SSH session is active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A remote session is useless if the laptop suspends mid-command, but logind doesn't suppress lid-close or idle-suspend for SSH sessions on its own — you have to hold an explicit inhibitor lock. When $SSH_CONNECTION is set, re-exec the login shell under `systemd-inhibit --what=sleep:idle:handle-lid-switch --mode=block` so the lock is bound to the shell's lifetime: it covers swayidle, logind's HandleLidSwitch, and any other consumer that respects inhibit locks, and it's released the moment the SSH session ends. A guard env var prevents recursion if the user nests a login shell inside the wrapped one (e.g. `exec zsh -l`). --- dot_config/zsh/dot_zprofile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'dot_config/zsh/dot_zprofile') diff --git a/dot_config/zsh/dot_zprofile b/dot_config/zsh/dot_zprofile index 7b79af0..02991cb 100644 --- a/dot_config/zsh/dot_zprofile +++ b/dot_config/zsh/dot_zprofile @@ -150,6 +150,23 @@ case $(uname -n) in ;; esac +# ── SSH: inhibit suspend/idle while connected ──────────────────────────────── +# A remote session is useless if the laptop suspends mid-command. Wrap the +# login shell in `systemd-inhibit` so a lock is held for the entire SSH +# session lifetime (lid close, idle timeout, swayidle, lid-switch handlers +# all honour it). The lock is released the instant the shell exits, so a +# clean disconnect restores normal power behaviour. +if [[ -n $SSH_CONNECTION && -z $__SSH_SUSPEND_INHIBITED ]] \ + && command -v systemd-inhibit >/dev/null 2>&1; then + export __SSH_SUSPEND_INHIBITED=1 + exec systemd-inhibit \ + --what=sleep:idle:handle-lid-switch \ + --who="ssh:${USER}@${HOST}" \ + --why="active SSH session from ${SSH_CONNECTION%% *}" \ + --mode=block \ + "$SHELL" -l +fi + # ── Auto-start sway on VT1 ──────────────────────────────────────────────────── if [[ -z $WAYLAND_DISPLAY && $XDG_VTNR == 1 ]]; then export XDG_SESSION_TYPE=wayland -- cgit v1.3.1