From 03835c5d8d1e1118787a3ce5c1bbc5e999e27581 Mon Sep 17 00:00:00 2001 From: druckdev Date: Tue, 27 Jul 2021 15:33:44 +0200 Subject: [PATCH] zsh:zprofile: Attach to tmux when connected by ssh --- .config/zsh/.zprofile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index c426488..aa8ebfb 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -102,3 +102,18 @@ if command -v startx &>/dev/null && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then startx exit $? fi + +# Attach to tmux session if connected over ssh and not already attached +if [[ (-n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION) && -z $TMUX ]]; then + num_sessions="$(tmux list-sessions 2>/dev/null | wc -l)" + + if (( ! num_sessions )); then + tmux + elif (( num_sessions == 1 )); then + tmux attach + else + tmux attach\; choose-tree -Zs + fi + + unset num_sessions +fi