From b4b2ac91c247116d0b4e0d0f8fee09e96951766b Mon Sep 17 00:00:00 2001 From: daniel fusser Date: Wed, 8 Jul 2026 19:35:47 +0200 Subject: [PATCH] mksh: auto-attach a shared tmux session per host on login Guarded to only fire for interactive shells with a real tty, when tmux isn't already active, and only if the tmux binary is found - so it falls back to a plain shell if any of that isn't true. Not exec'd, so an unexpected tmux exit also drops back to a normal shell instead of closing the connection. Replaces manually running bin/tmx. Co-Authored-By: Claude Sonnet 5 --- mksh/mkshrc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mksh/mkshrc b/mksh/mkshrc index 87859a7..63df11f 100644 --- a/mksh/mkshrc +++ b/mksh/mkshrc @@ -215,3 +215,11 @@ PS4='[$EPOCHREALTIME] '; PS1='#'; (( USER_ID )) && PS1='→'; PS1=$'\001\r''${| \\builtin return $e } '"${hostcol}${bld}$PS1 ${rst}" + +# tmux auto-attach: one shared session per host. No -exec, so if tmux is +# missing or exits/crashes for any reason, this shell just continues normally. +tmuxbin=$(\\builtin whence -p tmux 2>/dev/null) +if [[ $- = *i* ]] && [[ -t 0 ]] && [[ -z $TMUX ]] && [[ -n $tmuxbin ]]; then + "$tmuxbin" new-session -A -s "${HOSTNAME:-main}" +fi +unset tmuxbin