How to launch a set of program inside tmux or gnome-terminal within a script?
Open a tmux session and start the first command. Then launch more commands on new windows and evenly distribute the window sizes at the end.
tmux \
new-session "command1 ; read" \; \
split-window "command2 ; read" \; \
split-window "command3 ; read" \; \
split-window "command4 ; read" \; \
select-layout even-vertical
The read
after each command causes the window to stay open after the command has finished so that you can read the output.
tmux new -d -s my-session 'echo window-1 pane-1; sleep 8' \; \
split-window -d 'echo window-1 pane-2; sleep 6' \; down-pane \; \
new-window -d 'echo window-2; sleep 4' \; next-window \; \
attach \;
The above is a running example of the general idea ... more here: How to run streamripper and mplayer in a split-screen X terminal, via a single script
If it's always the same configuration of programs, you can use a tool like teamocil.
You'll need to create with a configuration (e.g. ~/.teamocil/sample
), which contains something like:
windows:
- name: my-first-window
root: ~/Projects/foo-www
filters:
before: "rvm use 1.9.2"
after: "echo 'I am done initializing this split.'"
splits:
- cmd: "git status"
- cmd: "bundle exec rails server --port 4000"
width: 50
- cmd:
- sudo service memcached start
- sudo service mongodb start
height: 50
And then you can run: tmux new-session -d "teamocil sample" \; attach