Add scrollback dump functionality

This commit is contained in:
Bruno Sutic 2014-05-27 12:04:21 +02:00
parent 180815614b
commit 67386c3260
2 changed files with 41 additions and 0 deletions

View file

@ -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

34
scripts/tmux_scrollback_dump.sh Executable file
View file

@ -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