【问题标题】:tmux: programatically split a window horizontally and run two commands?tmux:以编程方式水平拆分窗口并运行两个命令?
【发布时间】:2016-03-02 17:40:54
【问题描述】:

(欺骗说明) 这不是How to set up tmux so that it starts up with specified windows opened? 的欺骗。该问题围绕配置 tmux 展开,那里的答案都没有提供该问题的答案。 (尾注)

假设我有两个命令

tail -f log1
tail -f log2

如何以编程方式调用 tmux 以水平拆分窗口并在其自己的窗格中运行每个命令,类似于:

for i in log1 log2; do xterm -e tail -f $i& done

【问题讨论】:

  • 不是骗子。我对配置 tmux 启动不感兴趣,只对如何按照描述拆分当前窗口并运行命令感兴趣。没有一个问题能回答这个问题。
  • 请注意,我正在寻找可以执行此操作的单个调用。您的评论涉及手动输入两个命令。
  • 你想要什么?我为您提供了单个命令的链接,并解释了在会话中可以手动输入的命令。它们都适合您的用例。
  • 我觉得我有点笨...我没有看到您链接到的单个命令。尝试提供答案作为答案,看看我如何更新以显示 xterm 示例。将不胜感激,因为我的愚蠢使我无法理解您在说什么。

标签: linux macos tmux


【解决方案1】:

没有单一的命令可以做到这一点;相反,您向服务器发送多个命令。不过,这可以通过一次调用 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"

【讨论】:

  • 完美,谢谢。我修复了第一个示例,删除了外部单引号。
猜你喜欢
  • 2018-06-29
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多