简体   繁体   中英

How can I split my screen in 3 using tmux from a bash script

I'm writing a bash script that splits the screen in 3 and runs a command on each pane.

I basically want to run the bash script and the bash script is supposed to split my screen in 3, and run top in a pane, htop in the other pane and a perl re.pl in the third pane for example

any help or pointers are apprecieted!

The direct way to do this is to create a detached session, create the panes, then attach to the session.

# -d says not to attach to the session yet. top runs in the first
# window
tmux new-session -d top
# In the most recently created session, split the (only) window
# and run htop in the new pane
tmux split-window -v htop
# Split the new pane and run perl
tmux split-pane -v perl re.pl
# Make all three panes the same size (currently, the first pane
# is 50% of the window, and the two new panes are 25% each).
tmux select-layout even-vertical
# Now attach to the window
tmux attach-session

You can also do this in one call to tmux, but there probably is no reason to do this from a script:

tmux new-session -d top \; split-window -v htop \; split-window -v perl re.pl \; select-layout even-vertical \; attach-session

I am using tmuxinator for this. It lets you define windows and panes per window in a configuration file that you can then use with:

tmuxinator start <some-name>

It is really neat!

(I am sure it is possible to do this with pure bash also.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM