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:
Instead when all the commands are written in tmux it produces the desired output.
The picture indicates output produced when commands are manually typed:
How can the code be modified to produce the desired outcome?
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.
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.
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.
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.
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.
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