How do I get tmux to open up a set of panes without manually entering them?

Your configuration file is working, but there are a couple of complications.

Short-lived Commands

First, the commands you are starting (instances of ls) finish running very quickly. The windows and panes for the commands are created, but they disappear as soon as each command exits.

If your goal is to actually use such “one shot” commands in your eventual configuration, then you should probably use the window option remain-on-exit (and possibly the session option set-remain-on-exit to provide a default for all windows created in the session). When remain-on-exit is set for a window, it will not disappear when the command exits. You will probably want to map the respawn-window to a key (note: respawn-window will respawn the original command; respawn-pane is also available in tmux 1.5 to respawn individual panes).

bind-key R respawn-window

# set global r-o-e so that initial window of initial session gets it
set -g set-remain-on-exit on

# create a session and its windows/panes
new -n estruct ls
neww -n estruct2 ls
splitw -v -p 50 -t 0 ls

# restore global r-o-e
set -g set-remain-on-exit off

# let session r-o-e inherit from global value for future windows
set -u set-remain-on-exit

Or, if you do not mind your initial window being number 1 instead of number 0, then we can avoid changing the global value:

bind-key R respawn-window

# create a session with a throw-away window
new true

# for future windows, stay open after the command exits
set set-remain-on-exit on

# create the windows we really want
neww -n estruct ls
neww -n estruct2 ls
splitw -v -p 50 -t 0 ls

# for future windows, revert r-o-e to global value
set -u set-remain-on-exit

If you were only using ls as a simplified placeholder command and you actually intend to spawn some type of interactive command in your windows/panes, then you should probably just spawn the command you intended to eventually run. If your intended command takes too long to startup to use it during tmux testing, then substitute a shell or other simple interactive command (e.g. top, sqlite3, etc.).

new-session Is the Default Command

Second, running tmux without a command argument (e.g. tmux) is equivalent to using the new-session command (i.e. tmux is the same as tmux new-session). Your .tmux.conf creates a session for its windows/panes (new is an alias for new-session) and another session is being created for the implicit new-session command specified by starting tmux without a command argument. If you are using the default status bar, you will see a [1] in the left side of the status bar when you are in the “extra” session (the initial session created in the .tmux.conf is number 0).

If you want to avoid creating the extra session, then use tmux attach instead of plain tmux. The commands from your .tmux.conf will run, creating session 0, and then your client will attach to that session instead of creating a new one.


I'm not sure I understand what you mean by "manually entering", but this is how I do it. I wrote an "autostart" script that my window manager launches. It contains:

tmux start-server                                                                                                                                                                                                                                                                                                                                                            
for i in ~/sessions_tmux/*.session; do "$i"; done

where each .session file looks something like this:

#!/bin/bash

SESSION_NAME="flaskr_tutorial"
if [[ ! -z "$TMUX" ]] || [[ ! -z "$TMUX_PANE" ]]; then
    echo "Already inside a tmux session, do not know what to do"
    exit 1
fi
tmux -q has-session -t "$SESSION_NAME"
if [ $? ]; then
    exit 0
fi
NEWCWD=~/projects/flaskr/
( cd "${NEWCWD}"; tmux new-session -d -s "$SESSION_NAME" )
tmux send-keys -t "$SESSION_NAME" 'vim flaskr.py' Enter
( cd "${NEWCWD}"; tmux split -h -t "$SESSION_NAME" )
tmux send-keys -t "$SESSION_NAME" 'sudo tail -F -n 100 /var/log/messages | ccze' Enter

Wait, there's more! I have an ever growing number of .session files that I load up with konsole:

konsole --background-mode --profile Shell --tabs-from-file ~/sessions_tmux/work_console.tabs

where work_console.tabs looks something like this:

.
.
.
title: projectx;;    command: tmux attach -t projectx
title: flaskr;;      command: tmux attach -t flaskr_tutorial
.
.
.

Then I press F12 to launch konsole.


suppose you want to launch 3 server monitoring tasks (here ping localhost) there's no need to mess with configuration files and saved sessions. It can all be done from the command-line.

tmux new-session 'ping  127.0.0.1' \; \
    split-window 'ping  127.0.0.1' \; \
    split-window 'ping  127.0.0.1' \; \
    select-layout even-vertical