From 3b29820957b22e474a10172254fc515e4dfbdb60 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 7 Apr 2022 16:14:03 +0200 Subject: [PATCH] zprofile: Use `exec` when attaching to `tmux` When connected over ssh and attaching to/creating a tmux session, the shell should `exec` the tmux command so that detaching from the session automatically also closes the ssh connection. If something should happen and the `tmux` command bricks the remote shell this can fixed by logging in with: ssh [destination] zsh -dfi --- .config/zsh/.zprofile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index eda7bc7..e18df00 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -111,7 +111,7 @@ fi if (( $+commands[tmux] )) && [[ (-n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION) && -z $TMUX ]] then - TMUX_CMD=(tmux -f "${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf") + TMUX_CMD=(exec tmux -f "${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf") num_sessions="$("${TMUX_CMD[@]}" list-sessions 2>/dev/null | wc -l)" if (( ! num_sessions )); then @@ -124,3 +124,5 @@ then unset TMUX_CMD num_sessions fi +# NOTE: nothing should be placed behind this except for stuff that is sure that +# `tmux` was not called