sessions

24 views
Skip to first unread message

Michael Grant

unread,
Jun 26, 2025, 2:10:36 PMJun 26
to tmux-users
At the moment as I debug, I am starting tmux and creating new sessions and exiting.  I use `new -d` to create a new session.  I can't help but think there should be a way to create a new session and switch to it.  What I end up doing is this:
```
tmux switch-client -t `tmux new -d -P`
```
If you run `new` without any args one gets this message `sessions should be nested with care, unset $TMUX to force`.  Would it be terrible if instead of this message that tmux created a new session and switched to it like above?  

and... when I exit a the last window in a session, tmux exits.  But if there's more sessions, I have to run `tmux attach` to get back to one.  Instead of exiting, is there an option or would it be desirable for tmux to switch to one of the other sessions if there is one instead of exiting?  Like when you close a window.  To not break existing behaviour, if there isn't an option already to do this would likely intail a new option.

and lastly... before I understood sessions, I would often create them and then close the last window, tmux exits, and then i would run `tmux` again and I would end up with several sessions without knowing it!  Is there some option or command line arg I could use to attach if there was an existing session or start a new session if not?  I couldn't find one.  Best I could find was to set tmux as a shell alias to:

tmux attach || tmux

It doesn't bother me to create an alias to do this but I do wonder how many other people fall into the session trap without knowing and I do wonder if just running tmux without args should probably try to attach first.  I know this would change existing...

Michael Grant



Nicholas Marriott

unread,
Jun 26, 2025, 2:22:33 PMJun 26
to Michael Grant, tmux-users
Hi

I think that would be unexpected and the current behaviour is better.

I don't think we need a flag to build-in every conceivable behaviour, tmux is meant to be easily scriptable with the shell and your example seems tidy enough.

You can change detach-on-destroy or use -f no-detach-on-destroy to not detach when the session is destroyed.

tmux new -A should be equivalent to tmux attach || tmux new.


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/tmux-users/8516677a-1534-4ebb-b9e6-8cc8e56f19aan%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages