14

With TMux, is there any way to programmatically retrieve scroll buffer content from above the current command line?

I'm basically looking to write a bash script to iterate upwards until I find a matching string. To be clear, I don't want to go through history of typed commands; I want to go through everything that appeared on the console.

1 Answer 1

23

With tmux 1.5 (and later), you can give negative numbers to the -S option of capture-pane to access the scroll back buffer.

Examples:

  • Capture (up to) 32768 lines of the scroll back buffer along with the pane’s current text:

    tmux capture-pane -pS -32768
    
  • Capture just the tenth most recently “scrolled off” line:

    tmux capture-pane -pS -10 -E -10
    
  • Capture (up to) the 100 most-recently “scrolled off” lines:

    tmux capture-pane -pS -100 -E -1
    
  • Capture eleven lines that straddle the current top line of the pane (5 “scrolled off” lines, and the top 6 lines of the pane):

    tmux capture-pane -pS -5 -E 5
    

Note: As with most tmux commands, you can use -t to target a specific pane if the “current” pane is not the one you are interested in probing.


The above examples also use the -p option to capture-pane, which is only available starting in tmux 1.8. With older versions you could work around not having it by using save-buffer:

tmux capture-pane -S -32768 \; save-buffer - \; delete-buffer
1
  • Great, running this against any pane is even better than hoped for.
    – mahemoff
    Apr 21, 2014 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.