fix(tmux): improve tmuxsess behaviour

This commit is contained in:
Rob Watson 2023-10-01 16:19:24 +02:00
parent 431566d260
commit b99a48d09a
1 changed files with 16 additions and 1 deletions

View File

@ -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