title: How to wait for some text to show up in a pane
body: <p>In a shell script, I would love to be able to send keys to a tmux session after waiting for commands to change something in a pane. </p>
  
  <p>Here is one of my use cases:</p>
  
  <pre><code>tmux send-keys -t ...  'vi .' c-m # This opens NERDTree
  sleep 3                           # Sometimes sleep 2 is not enough
  tmux send-keys -t ...  c-w l      # Go to tab right
  </code></pre>
  
  <p>The commands can trigger the send key command by means of their output, but if there is a better way I would be listening.</p>
  
  <p>First idea I had, and is actually ok for my simple first use case, was a clumsy </p>
  
  <pre><code>  function wait_for_text_event
    {
         while :; do
            tmux capture-pane -t ... -p | grep "string triggering completion" &amp;&amp; return 0
         done
         # never executed unless a timeout mechanism is implemented
         return 1
    }
  </code></pre>
  
  <p>Now I can do</p>
  
  <pre><code>tmux send-keys -t ... 'vi .' c-m
  wait_for_text_event 'README.md'   # meaning NERDTree has opened the split window
  tmux send-keys -t ...  c-w l      # Go to tab right
  </code></pre>
  
  <p><strong>However</strong>
  Implementing timeouts gets already tricky in shell and the busy wait is ugly anyway.</p>
  
  <p>Is there some command (or way to implement it) which would just block until some
  text shows up in a pane e.g.</p>
  
  <p>tmux wait-for-text -t ... "Hello World" &amp;&amp; tmux send-keys ...</p>
  
  <p>possibly with a timeout.</p>
  
  <p>Or maybe I am approaching this the wrong way?</p>