Start tmux automatically
I wanted to start
tmux—the terminal multiplexer—automatically when I opened a new terminal window.
I had some specific requirements however. For instance, I wanted to have a “main” tmux session that new windows should try to attach to. And if I was already attached to the main tmux session, then I wanted any subsequent new terminal windows to create new unnamed sessions (this way each window has its own independent session).
- If the “main” session doesn’t exist, create a new session named “main”.
- If the “main” session exists and there are zero clients attached to it, attach to it ourselves.
- If the “main” session exists and there is already a client attached to it, create a new unnamed session.
I wrote a script to do this, since it seems like tmux’s built-in subcommands and flags can’t account for these requirements on their own. The command
tmux new -A -s main...
Continue reading →