svg

Tmux Config to Captures Up To 100000 Lines of History From The Current Pane

linux tmux

While browsing HackerNews today, I came across a comment from Tsiklon that really struck a chord with me.

…I tend to make use of the following command - which will output the last 100000 lines of the current pane to a text file local to you; it’s useful for documenting screwups, maintenance work, and of course making notes on what you’ve done for future reference bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -100000 ; save-buffer %1 ; delete-buffer'

This tip was exactly what I needed. It’s a clever and efficient way to save a large chunk of my terminal session for later reference. I immediately added it to my tmux configuration, with a small tweak to prompt me for a filename each time:

bind P command-prompt -p "Save history to filename:" "capture-pane -S -100000 \; save-buffer %1 \; delete-buffer"

Now, I can capture up to 100,000 lines of history from the current tmux pane with a single keystroke. It’s perfect for documenting work, troubleshooting, or just keeping notes for future reference!