如何从会话外部获取 tmux 会话中当前行的内容?

How do I get the contents of the current line inside a tmux session from outside the session?

我有一个分离的 tmux session that start a program that takes a few minutes to fully start. Once started, it provides a prompt within the program that can run certain commands specific to that program. When that prompt appears, I want to enter a specific command. I know I can send keystrokes with send-keys,所以问题归结为确定 shell 会话中当前行的内容何时是程序的提示。

请注意,从 shell 的角度来看,没有任何东西“停止 运行”,因此任何仅检查当前 shell 命令是否已完成的方法都不会工作。

我该怎么做?

看起来 capture-pane 就是答案。将当前窗格写入日志文件,然后使用 grep -q “<prompt>” ./tmux.log 查找当前行。 (这假设只有一行包含要搜索的文本,这在我的特定用例中是正确的。)