Reputation: 151
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?
Upvotes: 15
Views: 14665
Reputation: 530853
You can execute all the tmux
commands in a single invocation:
tmux new-session -d \; split-window -h \; split-window -h\; split-window -v
Upvotes: 0
Reputation: 21
#!/bin/bash
ssh_list=( `cat $1` )
split_list=()
round=0
i=0
for ssh_entry in "${ssh_list[@]:1}"; do
if (( $((round%2)) == 0 ))
then
split_list+=( split-window -v -t $((2*i)) -p 50 ssh "$ssh_entry" ';' )
else
split_list+=( split-window -h -t $((2*i)) -p 50 ssh "$ssh_entry" ';' )
fi
mxrd=$((2**round))
i=$((i+1))
if ((round==0)) || ((i>=mxrd))
then
i=0
round=$((round+1))
fi
done
tmux new-session ssh "${ssh_list[0]}" ';' \
select-layout tiled ';' \
"${split_list[@]}" \
set-option -w synchronize-panes
Upvotes: -1
Reputation: 809
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.
Upvotes: 7