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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With