从 tmux 命令行创建新窗格
Create new pane from tmux command line
我有一个启动 tmux 服务器并在会话中创建五个 windows 的脚本。然后它将所有窗格合并为一个 Window 以形成一个五 window 平铺窗格:
#!/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
有没有办法通过直接先创建五个窗格来优化它window(而不是先创建单独的windows然后合并)?
解决方案
#!/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
是的,使用 split-window 而不是 new-window...
我有一个启动 tmux 服务器并在会话中创建五个 windows 的脚本。然后它将所有窗格合并为一个 Window 以形成一个五 window 平铺窗格:
#!/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
有没有办法通过直接先创建五个窗格来优化它window(而不是先创建单独的windows然后合并)?
解决方案
#!/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
是的,使用 split-window 而不是 new-window...