From b99a48d09a0c61d736e74911269822d125fff3a2 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Sun, 1 Oct 2023 16:19:24 +0200 Subject: [PATCH] fix(tmux): improve tmuxsess behaviour --- script/tmuxsess | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/script/tmuxsess b/script/tmuxsess index 297fd07..5e22588 100755 --- a/script/tmuxsess +++ b/script/tmuxsess @@ -13,7 +13,22 @@ if [ -z "$1" ]; then else sessionname="$1" fi -tmux new -d -s $sessionname + +tmux_new_result=$(tmux new -d -s $sessionname 2>&1) || true +exitcode=$? + +if echo "$tmux_new_result" | grep -q "duplicate session"; then + echo "Session $sessionname already exists. Attaching..." + tmux new -d -A -s $sessionname + exit 0 +fi + +if [ $exitcode -ne 0 ]; then + echo "$tmux_new_result" + exit $exitcode +fi + +# TODO: fix sessionname containing full stop which are renamed by tmux tmux rename-window -t $sessionname:1 cli tmux new-window -t $sessionname -n vim zsh -ic nvim tmux select-window -t $sessionname:1