Files
Kamino/roles/system_baseline/templates/tmux-autostart.sh.j2
T
Dragonish da3389eac1
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Successful in 21s
Molecule / molecule (pull_request) Successful in 1m30s
fix(system_baseline): keep tmux autostart from ending or swallowing logins
Review of #122.

- A failed attach no longer closes the connection: the snippet does not exec tmux, it
  prints a line and leaves the plain shell (a client TERM without terminfo made every
  login fail). A clean detach still ends the connection.
- The snippet acts only for an interactive shell (case $-): a login shell that is not
  interactive, such as `ssh -t host 'bash -lc cmd'`, is left alone. Docs corrected.
- Validation anchors with \Z, so a trailing newline from a YAML block scalar is refused.
  It moves to validate.yml (tag always); argument_specs already covers types.
- Install keys on tmux being in the resolved package list, not a second profile list.
- verify.yml: the snippet does nothing without a terminal, the trailing-newline refusals,
  and the removal path. The vacuous pve assert is gone.
- README and argument_specs: window commands start with a minimal environment (use absolute
  paths), zsh and fish do not read /etc/profile.d, detach ends the connection.
2026-11-14 16:34:14 +00:00

23 lines
1.6 KiB
Django/Jinja

# Managed by Ansible (mortis.kamino.system_baseline, tasks/tmux.yml). Do not edit: the next run overwrites it.
# Interactive login shells with a terminal and an SSH connection only: scp, sftp, `ssh host command` and Ansible have no terminal
# or no interactive shell, and `ssh -t host 'bash -lc cmd'` is a login shell that is not interactive (the case below keeps it out).
# Off for one user: touch ~/.no-tmux
case $- in
*i*)
if [ -n "$SSH_CONNECTION" ] && [ -z "$TMUX" ] && [ -t 0 ] && [ ! -e "$HOME/.no-tmux" ] && command -v tmux >/dev/null 2>&1; then
# new-session -d fails when the session exists, so the windows below are made only when this login creates it (once, even
# for two logins at the same moment). Windows close when their command exits; window 0 is always a plain shell.
if tmux new-session -d -s {{ system_baseline_tmux_session | quote }} 2>/dev/null; then
:
{% for window in system_baseline_tmux_windows %}
tmux new-window -d -t {{ ('=' ~ system_baseline_tmux_session ~ ':') | quote }} -n {{ window.name | quote }} {{ window.command | quote }}
{% endfor %}
fi
# Not exec: a failed attach (for example a client TERM this host has no terminfo for) must leave a usable shell instead of
# closing the connection on every login. A clean detach exits, so detaching ends the SSH connection.
tmux attach-session -t {{ ('=' ~ system_baseline_tmux_session) | quote }} && exit
echo 'tmux-autostart: could not attach to tmux, continuing with a plain shell (touch ~/.no-tmux to stop trying)' >&2
fi
;;
esac