【问题标题】:How can I split my screen in 3 using tmux from a bash script如何使用 bash 脚本中的 tmux 将屏幕一分为三
【发布时间】:2016-06-23 07:10:33
【问题描述】:

我正在编写一个 bash 脚本,它将屏幕分成 3 部分并在每个窗格上运行一个命令。

我基本上想运行 bash 脚本,而 bash 脚本应该将我的屏幕分成 3 部分,然后在一个窗格中运行 top,在另一个窗格中运行 htop,在第三个窗格中运行 perl re.pl

感谢任何帮助或指点!

【问题讨论】:

    标签: linux bash tmux


    【解决方案1】:

    执行此操作的直接方法是创建分离会话,创建窗格,然后附加到会话。

    # -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-pane 在 2.3 的文档中不可用,由于某种原因 manpages.ubuntu.com/manpages/zesty/en/man1/… 尽管 tmux 在实际使用 split-pane 时不会抱怨
    • 嗯。我不能说它何时或为何被移除,但看起来split-window -t <pane> 是替代品。 (想一想,单独的 split-windowsplit-pane 命令似乎是多余的;您实际上从未拆分窗口,因为所有窗口都至少包含一个窗格。)
    • 您可以在 tmux 内部执行此操作。制作三个窗格(2xC-b "),然后使用C-b : 进入命令模式并输入select-layout even-vertical(或even-horizontal,我觉得这样更有用)
    • 问题是专门编写一个脚本来执行此操作,而无需 C-b " 需要的手动干预。
    • 对不起,我错过了,当我在交互使用时有这个愿望时,这对我很有帮助。
    【解决方案2】:

    我为此使用tmuxinator。它允许您在配置文件中为每个窗口定义窗口和窗格,然后您可以使用:

    tmuxinator start <some-name>
    

    真的很好看!

    (我相信纯 bash 也可以做到这一点。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-16
      • 2011-11-21
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2015-02-08
      相关资源
      最近更新 更多