How to start tmux with several panes open at the same time?

Another option is to create an alias or another shell file in /bin for:

tmux new-session \; split-window -h \; split-window -v \; attach

or

tmux source-file ~/.tmux.conf

where ~/.tmux.conf

new
neww
splitw -h
splitw -v

For reference, same question has other options in SE, How to set up tmux so that it starts up with specified windows opened?


You can use following shell script for your configuration:

#!/bin/sh 
tmux new-session -s "mySession" -d
tmux split-window -h
tmux split-window -v
tmux -2 attach-session -d 

This will give the required configuration of the screen with following commands as you mentioned. tmux --> Ctrl+b+% --> Ctrl+b+"

For reference please use tmux man page.


It can be easy to enable and disable automatic tmux sessions on login by using Byobu application. You can use Byobu as an interface to tmux to address this need, it makes it simple to do what you are asking. In a terminal, run following commands:

sudo apt-get install byobu
sudo byobu-enable
sudo -i

When the root user logs in via the console, SSH, or with sudo -i, Byobu will attach to an existing tmux session or create a new one if one is not already running. Use sudo -i instead of sudo -s. The -s option only starts a shell, not a login shell. You should use sudo -i to emulate a full login, which also loads roots ~/.profile, and this is where byobu will install itself when you run

byobu-enable.

You can configure different sessions from your .tmux.conf as below:

# initialize sessions
bind S source-file ~/.tmux/session1 
bind s source-file ~/.tmux/session2

And then you can format the sessions as you require:

#session1
new  -s SessionName -n WindowName Command
neww -n foo/bar foo
splitw -v -p 50 -t 0 bar
selectw -t 1 
selectp -t 0

This would open 2 windows, the second of which would be named foo/bar and would be split vertically in half (50%) with foo running above bar. Focus would be in window 2 (foo/bar), top pane (foo).

Byobu makes setting up and starting tmux automatically very simple.

Tags:

Tmux