Search code examples
bashtmux

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


I have a detached 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, so the question boils down to determining when the contents of the current line in that shell session is the program's prompt.

Please note that from the shell's perspective, nothing has "stopped running", and so any methods that simply check if the current shell commands have completed will not work.

How do I do this?


Solution

  • It looks like capture-pane is the answer. Write the current pane to a log file, then find the current line using grep -q “<prompt>” ./tmux.log. (This assumes there will only be a single line with the text being searched for, which is true in my specific use case.)