tmux:以编程方式水平拆分 window 和 运行 两个命令?
tmux: programatically split a window horizontally and run two commands?
(欺骗注释) 这不是 How to set up tmux so that it starts up with specified windows opened? 的欺骗。该问题围绕配置 tmux 展开,那里 none 的答案提供了该问题的答案。 (尾注)
假设我有两个命令
tail -f log1
tail -f log2
我如何以编程方式调用 tmux 以水平拆分 window 和 运行 每个命令在其自己的窗格中,类似于:
for i in log1 log2; do xterm -e tail -f $i& done
没有一个命令可以完成这个;相反,您向服务器发送多个命令。不过,这可以通过一次调用 tmux
.
来完成
tmux new-session -d tail -f log1 \; split-window tail -f log2 \; attach
请注意,转义分号用于分隔 tmux
命令。未转义的分号被视为由特定 tmux
命令执行的 shell 命令的一部分。
调整问题中的循环可能类似于:
tmux_command="new-session -d"
commands=("tail -f log1" "tail -f log2" "tail -f log3")
tmux_command+=" ${commands[0]}"
for cmd in "${commands[@]:1}"; do
tmux_command+="\; split-window $cmd"
done
tmux "$tmux_command \; attach"
(欺骗注释) 这不是 How to set up tmux so that it starts up with specified windows opened? 的欺骗。该问题围绕配置 tmux 展开,那里 none 的答案提供了该问题的答案。 (尾注)
假设我有两个命令
tail -f log1
tail -f log2
我如何以编程方式调用 tmux 以水平拆分 window 和 运行 每个命令在其自己的窗格中,类似于:
for i in log1 log2; do xterm -e tail -f $i& done
没有一个命令可以完成这个;相反,您向服务器发送多个命令。不过,这可以通过一次调用 tmux
.
tmux new-session -d tail -f log1 \; split-window tail -f log2 \; attach
请注意,转义分号用于分隔 tmux
命令。未转义的分号被视为由特定 tmux
命令执行的 shell 命令的一部分。
调整问题中的循环可能类似于:
tmux_command="new-session -d"
commands=("tail -f log1" "tail -f log2" "tail -f log3")
tmux_command+=" ${commands[0]}"
for cmd in "${commands[@]:1}"; do
tmux_command+="\; split-window $cmd"
done
tmux "$tmux_command \; attach"