【发布时间】:2016-06-23 07:10:33
【问题描述】:
我正在编写一个 bash 脚本,它将屏幕分成 3 部分并在每个窗格上运行一个命令。
我基本上想运行 bash 脚本,而 bash 脚本应该将我的屏幕分成 3 部分,然后在一个窗格中运行 top,在另一个窗格中运行 htop,在第三个窗格中运行 perl re.pl
感谢任何帮助或指点!
【问题讨论】:
我正在编写一个 bash 脚本,它将屏幕分成 3 部分并在每个窗格上运行一个命令。
我基本上想运行 bash 脚本,而 bash 脚本应该将我的屏幕分成 3 部分,然后在一个窗格中运行 top,在另一个窗格中运行 htop,在第三个窗格中运行 perl re.pl
感谢任何帮助或指点!
【问题讨论】:
执行此操作的直接方法是创建分离会话,创建窗格,然后附加到会话。
# -d says not to attach to the session yet. top runs in the first
# window
tmux new-session -d top
# In the most recently created session, split the (only) window
# and run htop in the new pane
tmux split-window -v htop
# Split the new pane and run perl
tmux split-pane -v perl re.pl
# Make all three panes the same size (currently, the first pane
# is 50% of the window, and the two new panes are 25% each).
tmux select-layout even-vertical
# Now attach to the window
tmux attach-session
您也可以通过一次调用 tmux 来执行此操作,但可能没有理由通过脚本执行此操作:
tmux new-session -d top \; split-window -v htop \; split-window -v perl re.pl \; select-layout even-vertical \; attach-session
【讨论】:
split-window -t <pane> 是替代品。 (想一想,单独的 split-window 和 split-pane 命令似乎是多余的;您实际上从未拆分窗口,因为所有窗口都至少包含一个窗格。)
C-b "),然后使用C-b : 进入命令模式并输入select-layout even-vertical(或even-horizontal,我觉得这样更有用)
C-b " 需要的手动干预。
我为此使用tmuxinator。它允许您在配置文件中为每个窗口定义窗口和窗格,然后您可以使用:
tmuxinator start <some-name>
真的很好看!
(我相信纯 bash 也可以做到这一点。)
【讨论】: