Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

tmux

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!

like image 748
user2348668 Avatar asked Jun 21 '16 21:06

user2348668


People also ask

How do you split the screen on Tmux?

ctrl + b + % to make a vertical split. ctrl + b + " to make a Horizontal split. ctrl + b + left arrow to move to the left pane. ctrl + b + " to make a Horizontal split.

How do you split a window in Linux?

Here are the basic split commands, using the default keyboard shortcuts: Ctrl-A | for a vertical split (one shell on the left, one shell on the right) Ctrl-A S for a horizontal split (one shell at the top, one shell at the bottom) Ctrl-A Tab to make the other shell active.

How do you close a split in Tmux?

To close a pane, first ensure that you're positioned in it. Then type "exit" or Ctrl-d. Note that there is no need for Ctrl-b in this step. Once you type "exit" or Ctrl-d in the last remaining pane, tmux will close.


1 Answers

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
like image 115
chepner Avatar answered Sep 22 '22 04:09

chepner