Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux split-window using shell script

Tags:

shell

tmux

I am trying to write shell script for creating panes in tmux.

#!/bin/sh
tmux rename-window user
tmux new-session -d
tmux split-window -h
tmux selectp -t 1
tmux split-window -h
tmux select-layout even-horizontal
tmux selectp -t 2
tmux split-window -v

But when executing the above code doesn't produce desired output.

The picture indicates output produced when the code is executed:

Resulting output

Instead when all the commands are written in tmux it produces the desired output.

The picture indicates output produced when commands are manually typed:

Desired output

How can the code be modified to produce the desired outcome?

like image 923
ysiripragada Avatar asked Feb 05 '18 09:02

ysiripragada


People also ask

How do I split a window in 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 I split a terminal in tmux?

If you're using tmux primarily for screen splitting, then the only commands you really need are these: Ctrl-B % for a vertical split (one shell on the left, one shell on the right) Ctrl-B" for a horizontal split (one shell at the top, one shell at the bottom) Ctrl-B O to make the other shell active.

How do I open multiple windows in tmux?

To create multiple windows, you need at least one tmux session running. You can simply type CTRL + b, let go of both keys and type 'c'. This will open up a new terminal. At the bottom, you can see that there are now multiple windows (0, 1, 2) in the session.

How do I switch between tmux panes?

Tmux uses the keybinding 'Prefix' followed by 'Ctrl+o' to cycle around the panes. When you use this key-binding for the first time, it moves the pane in one position clockwise.


1 Answers

Try this, it looks like it does what you need (judging by the "Desired Output" image):

tmux split-window -h
tmux split-window -h
tmux select-layout even-horizontal
tmux split-window -v
tmux select-pane -t 0

You can also try persisting your layout using something like https://github.com/tmux-plugins/tmux-resurrect.

like image 82
atomicstack Avatar answered Oct 06 '22 23:10

atomicstack