linuxbashtmux

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!


Solution

  • 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