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