Tmux 在同一窗口中拆分窗格

Tmux 在同一窗口中拆分窗格

我是在脚本编写中使用 tmux 的新手,我正在尝试操纵它,因此当我运行脚本时,我可以在会话中附加和拆分多个屏幕Putty,并且还对其进行颜色编码和绑定,以便如果我使用ALT+arrow key它,它将切换到下一个窗格。这是我到目前为止的编码内容:

tmux new-session -d -s PortalDB
tmux selectp -t PortalDB
tmux splitw -h -p 50
tmux attach -t PortalDB
tmux set-window-option -g window-status-current-bg yellow
tmux new-session -d -s HardwareAgent
tmux selectp -t HardwareAgent
tmux splitw -h -p 50
tmux attach -t HardwareAgent
tmux set-window-option -g window-status-current-bg blue
tmux new-session -d -s Profile
tmux selectp -t Profile
tmux splitw -h -p 50
tmux attach -t Profile
tmux set-window-option -g window-status-current-bg red
tmux new-session -d -s JoinCode
tmux selectp -t JoinCode
tmux splitw -h -p 50
tmux attach -t JoinCode
tmux set-window-option -g window-status-current-bg green


tmux bind -n M-Left select-pane -L
tmux bind -n M-Right select-pane -R
tmux bind -n M-Up select-pane -U
tmux bind -n M-Down select-pane -D

当我运行脚本时,颜色编码有效,但是我希望它水平分割屏幕,但我得到的是:

结果

有人可以建议一种可以均匀分割窗格的方法吗?我注意到的另一件事是,当我运行这个脚本时,它会运行附加到我命名的会话的 4 个不同窗口,我只需要它在一个窗口中水平分割 4 次。谁能建议如何做到这一点?

答案1

我找到了一种更好的方法来编写此代码,而无需运行这么多 tmux,并且它可以完成我想要的大部分工作:

tmux new-window -a -n WinSplit
tmux new-session -d -s WinSplit
tmux selectp -t WinSplit
tmux split-window -v
tmux set-window-option -g window-status-current-bg blue
tmux split-window -v
tmux split-window -v
tmux select-layout even-vertical
tmux attach -t WinSplit

答案2

man tmux

split-window [-dhvP] [-l size | -p percentage] [-t target-pane]
             [shell-command]
                   (alias: splitw)
             Create a new pane by splitting target-pane: -h does a horizontal
             split and -v a vertical split; if neither is specified, -v is
             assumed.  The -l and -p options specify the size of the new pane
             in lines (for vertical split) or in cells (for horizontal split),
             or as a percentage, respectively.  All other options have the
             same meaning as for the new-window command.

所以你应该将所有内容更改splitw -hsplit -v垂直分割。

相关内容