diff --git a/proper_pipe_pane.tmux b/proper_pipe_pane.tmux index 1db6586..2fbaa72 100755 --- a/proper_pipe_pane.tmux +++ b/proper_pipe_pane.tmux @@ -6,6 +6,7 @@ source $CURRENT_DIR/scripts/shared.sh default_pipe_pane_key="P" default_pane_screenshot_key="M-p" # Alt-p +default_pane_scrollback_key="M-P" # Alt-Shift-p setup_pipe_pane_key_binding() { local pipe_pane_key=$(get_tmux_option "@ppp_pipe_pane_key" "$default_pipe_pane_key") @@ -17,8 +18,14 @@ setup_pane_screenshot_key_binding() { tmux bind-key "$pane_screenshot_key" run-shell "$CURRENT_DIR/scripts/tmux_pane_screenshot.sh" } +setup_pane_scrollback_key_binding() { + local pane_scrollback_key=$(get_tmux_option "@ppp_pane_scrollback_key" "$default_pane_scrollback_key") + tmux bind-key "$pane_scrollback_key" run-shell "$CURRENT_DIR/scripts/tmux_scrollback_dump.sh" +} + main() { setup_pipe_pane_key_binding setup_pane_screenshot_key_binding + setup_pane_scrollback_key_binding } main diff --git a/scripts/tmux_scrollback_dump.sh b/scripts/tmux_scrollback_dump.sh new file mode 100755 index 0000000..d7869e3 --- /dev/null +++ b/scripts/tmux_scrollback_dump.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +default_scrollback_path="$HOME" +default_scrollback_name="tmux-scrollback-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log" + +source $CURRENT_DIR/shared.sh + +get_scrollback_path() { + get_tmux_option "@ppp_scrollback_path" "$default_scrollback_path" +} + +# `tmux save-buffer` command does not perform interpolation, so we're doing it +# "manually" with `display-message` +get_scrollback_name() { + local name_template=$(get_tmux_option "@ppp_scrollback_name" "$default_scrollback_name") + tmux display-message -p "$name_template" +} + +scrollback_dump() { + local scrollback_path=$(get_scrollback_path) + local scrollback_name=$(get_scrollback_name) + # copying 9M lines back in the past will hopefully fetch all the history + tmux capture-pane -S -9000000 + tmux save-buffer "$scrollback_path/$scrollback_name" + tmux delete-buffer + display_message "Scrollback saved to $scrollback_path/$scrollback_name" +} + +main() { + scrollback_dump +} +main