【问题标题】:Create new pane from tmux command line从 tmux 命令行创建新窗格
【发布时间】:2019-08-09 20:30:42
【问题描述】:

我有一个脚本可以启动一个 tmux 服务器并在一个会话中创建五个窗口。然后它将所有的窗格连接到一个窗口中,形成一个五窗口的平铺窗格:

#!/usr/bin/env sh

tmux start-server

# create a session with five windows
tmux new-session -d -s MySession -n Shell1 -d "/usr/bin/env sh -c \"echo 'first shell'\"; /usr/bin/env sh -i"
tmux new-window -t MySession:1 -n Shell2 "/usr/bin/env sh -c \"echo 'second shell'\"; /usr/bin/env sh -i"
tmux new-window -t MySession:2 -n Shell3 "/usr/bin/env sh -c \"echo 'third shell'\"; /usr/bin/env sh -i"
tmux new-window -t MySession:3 -n Shell4 "/usr/bin/env sh -c \"echo 'fourth shell'\"; /usr/bin/env sh -i"
tmux new-window -t MySession:4 -n Shell5 "/usr/bin/env sh -c \"echo 'fifth shell'\"; /usr/bin/env sh -i"

# merge all panes in one window
tmux join-pane -t MySession:0 -s 1
tmux join-pane -t MySession:0 -s 2
tmux join-pane -t MySession:0 -s 3
tmux join-pane -t MySession:0 -s 4

# change layout to tiled
tmux select-layout -t MySession:0 tiled

tmux attach -tMySession

有没有办法通过直接在第一个窗口中创建五个窗格来优化它(而不是先创建单个窗口然后合并)?


解决方案

#!/usr/bin/env sh

tmux start-server

# create a session with five panes
tmux new-session -d -s MySession -n Shell1 -d "/usr/bin/env sh -c \"echo 'first shell'\"; /usr/bin/env sh -i"
tmux split-window -t MySession:0 "/usr/bin/env sh -c \"echo 'second shell'\"; /usr/bin/env sh -i"
tmux split-window -t MySession:0 "/usr/bin/env sh -c \"echo 'third shell'\"; /usr/bin/env sh -i"
tmux split-window -t MySession:0 "/usr/bin/env sh -c \"echo 'fourth shell'\"; /usr/bin/env sh -i"
tmux split-window -t MySession:0 "/usr/bin/env sh -c \"echo 'fifth shell'\"; /usr/bin/env sh -i"

# change layout to tiled
tmux select-layout -t MySession:0 tiled

tmux attach -tMySession

【问题讨论】:

  • 完美运行!我想补充一下:每 4 次拆分需要运行“tmux select-layout -t MySession:0 tiled”,否则新窗格将无法创建。

标签: tmux


【解决方案1】:

是的,使用拆分窗口而不是新窗口...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多