Sample Header Ad - 728x90

How can I attach to the the first unattached tmux session, or create a new session if there are no unattached sessions?

4 votes
4 answers
2352 views
How can I attach to the the first tmux session **that has no attached clients** or, if there are no unattached sessions, create a new session and attach to that? (The use case is for a command for my terminal emulator to run when opening a new terminal window. I don't want it to create a new session each time I open a window, if there are detached sessions lying around. Nor do I want it to re-attach to the same named session every time, if there's already a window attached to that session. I want it to recycle existing unattached sessions but create new sessions when there are none unattached.)
Asked by Sean Hammond (151 rep)
Jul 8, 2019, 09:39 PM
Last activity: Jul 29, 2025, 03:21 PM