When you log into your remote machine, you will want to either start tmux or attach to one that is already running (with tmux attach ). If you attempt those commands in the reverse order, you can do it with one command:

tmux attach || tmux

You don’t want to run that when you are already attached, so I check to make sure the TERM environment variable is not set to screen before running it.

I usually run this script (I call it t ) installed on each of my servers. I then log into the server via: ssh some-host -t ~/bin/t

if [ "$TERM" != "screen" ] then if type tmux >/dev/null 2 >& 1 then tmux att || tmux \ new -s Joseph -n shell \; \ neww -n mysql "mysql -u $DB_USER -p$DB_PASS $DB_NAME" \; \ neww -n ruby "irb" fi fi

The tmux executable can take commands where each command is separated with a \; (to escape it from the shell). While I split the commands on three lines, this is really a single line as the end of each line needs to have a continuation \ as the last character… again, this is a shell-ism.

The three lines following the tmux call specifies these starting commands:

The new creates a new “session” (see below for details), which starts a new shell session that I name (with the -n option) “shell” (yeah, how original). The neww creates a new virtual tab (or window) the first is called “mysql” and then runs the mysql executable. The last line creates a new tab named ruby and runs the irb command.