zsh:zprofile: Attach to tmux when connected by ssh

This commit is contained in:
2021-07-27 15:33:44 +02:00
parent 1c36ae8cac
commit 03835c5d8d

View File

@@ -102,3 +102,18 @@ if command -v startx &>/dev/null && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then
startx startx
exit $? exit $?
fi 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