首页 > 解决方案 > tmux 8 窗格“理智”平铺布局

问题描述

当我使用tmux8 个窗格时,它会像这样平铺它们:

在此处输入图像描述

但我希望它们像这样平铺:

在此处输入图像描述

有什么办法可以自动完成吗?

标签: tmux

解决方案


试试下面的 bash 脚本:

tmux new -s test -d

tmux selectp -t 0    # select the first (0) pane
tmux splitw -h -p 75 # split it into two horizontal parts
tmux selectp -t 0    # select the first (0) pane
tmux splitw -v -p 50 # split it into two vertical halves

# After this 3 panes will be created with pane number 0 (left- horizontal)
# Pane 1 (vertical pane under the pane 0)
# And Pane 2 with the remaining screen size 
# Then we divide this remaining pane 2 into three similar panes
# repeat this till all 8 panes are created

tmux selectp -t 2    # select the new, second (2) pane
tmux splitw -h -p 66 # split it into two halves
tmux selectp -t 2    # select the second (2) pane
tmux splitw -v -p 50 # split it into two vertical halves

tmux selectp -t 4    # select the new, fourth (4) pane
tmux splitw -h -p 50 # split it into two halves
tmux selectp -t 4    # select the fourth (4) pane
tmux splitw -v -p 50 # split it into two halves

tmux selectp -t 6    # select the new, sixth (6) pane
tmux splitw -v -p 50 # split it into two halves
tmux selectp -t 0    # go back to the first pane
tmux attach -t test

诀窍是识别pane number并相应地拆分它。将以下行添加到上述脚本中,您可以看到窗格编号以及tmux.

tmux send-keys -t 0 'echo "-- Pane 1 ---"' Enter
tmux send-keys -t 1 'echo "-- Pane 2 ---"' Enter
tmux send-keys -t 2 'echo "-- Pane 3 ---"' Enter
tmux send-keys -t 3 'echo "-- Pane 4 ---"' Enter
tmux send-keys -t 4 'echo "-- Pane 5 ---"' Enter
tmux send-keys -t 5 'echo "-- Pane 6 ---"' Enter
tmux send-keys -t 6 'echo "-- Pane 7 ---"' Enter
tmux send-keys -t 7 'echo "-- Pane 8 ---"' Enter

send-keys将命令发送echo "-- pane number --" 到选项指定的窗格-t


推荐阅读