The 5-line shell script that becomes your dev environment
Once you've used tmux for a week you'll notice a pattern: every morning you open the same project, create the same windows, run the same commands. tmux's command-line interface is rich enough to automate the whole sequence in a shell script. Run the script; the workspace is up.
The basic recipe
tmux's command-line accepts subcommands like new-session, send-keys, split-window. -d creates the session detached so you can keep configuring it; -t targets a session/window/pane; send-keys "cmd" C-m sends a string and a Carriage-Return (Enter).
tmuxinator — when shell scripts get gnarly
For complex layouts, tmuxinator is the YAML-based alternative. You describe the workspace declaratively; tmuxinator start project brings it up. It's a Ruby gem, and there are similar tools in other languages (tmuxp in Python). For most personal projects, a 10-line shell script is plenty.
Nested tmux over SSH
Common scenario: tmux running locally, you SSH into a server running its own tmux. Now Ctrl-a is ambiguous — does it go to your local prefix or the remote one? Two clean solutions:
- Different prefixes per machine. Local tmux uses
Ctrl-a, remote tmux usesCtrl-b(the default). No conflict. - Send-prefix binding. If you must use the same prefix on both, configure each so
Ctrl-a asends a literalCtrl-ato whatever's nested below. Hit it twice to talk to the inner tmux.
prefix + commands every morning, that's a script waiting to be written. Scripts cost minutes to write and save those minutes every day for the rest of the project.The discoverable detach
tmux detach-client, tmux switch-client -t name, tmux send-keys -t name 'cmd' Enter — every interactive key has a non-interactive command-line counterpart. That's how you automate.