mirror of
https://github.com/tmux-plugins/tmux-logging.git
synced 2026-09-10 07:16:28 -04:00
Refactor screenshot & scrollback scripts
This commit is contained in:
parent
1421d5b506
commit
386eec0bc6
34
scripts/capture_pane_helpers.sh
Normal file
34
scripts/capture_pane_helpers.sh
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Variables in this helper are set in the file sourcing the helper.
|
||||
|
||||
# Required variables:
|
||||
# - path_option & default_path
|
||||
# - name_option & default_name
|
||||
|
||||
get_path() {
|
||||
get_tmux_option "$path_option" "$default_path"
|
||||
}
|
||||
|
||||
# `tmux save-buffer` command does not perform interpolation, so we're doing it
|
||||
# "manually" with `display-message`
|
||||
get_filename() {
|
||||
local name_template=$(get_tmux_option "$name_option" "$default_name")
|
||||
tmux display-message -p "$name_template"
|
||||
}
|
||||
|
||||
capture_pane() {
|
||||
local capture_scope=$1
|
||||
local file=$2
|
||||
if [ $capture_scope == "Scrollback" ]; then
|
||||
# copying 9M lines back will hopefully fetch whole scrollback
|
||||
tmux capture-pane -S -9000000
|
||||
elif [ $capture_scope == "Screenshot" ]; then
|
||||
tmux capture-pane
|
||||
else
|
||||
# error
|
||||
exit 1
|
||||
fi
|
||||
tmux save-buffer "$file"
|
||||
tmux delete-buffer
|
||||
remove_empty_lines_from_end_of_file "$file"
|
||||
display_message "$capture_scope saved to $file"
|
||||
}
|
||||
|
|
@ -32,3 +32,10 @@ display_message() {
|
|||
# restores original 'display-time' value
|
||||
tmux set-option -gq display-time "$saved_display_time"
|
||||
}
|
||||
|
||||
# simplest solution, taken from here: http://unix.stackexchange.com/a/81689
|
||||
remove_empty_lines_from_end_of_file() {
|
||||
local file=$1
|
||||
local temp=$(cat $file)
|
||||
printf '%s\n' "$temp" > "$file"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,32 +2,18 @@
|
|||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
default_screenshot_path="$HOME"
|
||||
default_screenshot_name="tmux-screenshot-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
|
||||
# Functions defined in capture_pane_helpers are customized via below variables.
|
||||
default_path="$HOME"
|
||||
default_name="tmux-screenshot-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
|
||||
|
||||
path_option="@screenshot_path"
|
||||
name_option="@screenshot_filename"
|
||||
|
||||
source $CURRENT_DIR/shared.sh
|
||||
|
||||
get_screenshot_path() {
|
||||
get_tmux_option "@ppp_screenshot_path" "$default_screenshot_path"
|
||||
}
|
||||
|
||||
# `tmux save-buffer` command does not perform interpolation, so we're doing it
|
||||
# "manually" with `display-message`
|
||||
get_screenshot_name() {
|
||||
local name_template=$(get_tmux_option "@ppp_screenshot_name" "$default_screenshot_name")
|
||||
tmux display-message -p "$name_template"
|
||||
}
|
||||
|
||||
pane_screenshot() {
|
||||
local screenshot_path=$(get_screenshot_path)
|
||||
local screenshot_name=$(get_screenshot_name)
|
||||
tmux capture-pane
|
||||
tmux save-buffer "$screenshot_path/$screenshot_name"
|
||||
tmux delete-buffer
|
||||
display_message "Pane screenshot saved to $screenshot_path/$screenshot_name"
|
||||
}
|
||||
source $CURRENT_DIR/capture_pane_helpers.sh
|
||||
|
||||
main() {
|
||||
pane_screenshot
|
||||
local file="$(get_path)/$(get_filename)"
|
||||
capture_pane "Screenshot" "$file"
|
||||
}
|
||||
main
|
||||
|
|
|
|||
|
|
@ -2,42 +2,18 @@
|
|||
|
||||
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"
|
||||
# Functions defined in capture_pane_helpers are customized via below variables.
|
||||
default_path="$HOME"
|
||||
default_name="tmux-scrollback-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
|
||||
|
||||
path_option="@scrollback_dump_path"
|
||||
name_option="@scrollback_dump_filename"
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
# simplest solution, taken from here: http://unix.stackexchange.com/a/81689
|
||||
remove_empty_lines_from_end_of_file() {
|
||||
local file=$1
|
||||
local temp=$(cat $file)
|
||||
printf '%s\n' "$temp" > "$file"
|
||||
}
|
||||
|
||||
scrollback_dump() {
|
||||
local scrollback_path=$(get_scrollback_path)
|
||||
local scrollback_name=$(get_scrollback_name)
|
||||
local file="$scrollback_path/$scrollback_name"
|
||||
# copying 9M lines back in the past will hopefully fetch all the history
|
||||
tmux capture-pane -S -9000000
|
||||
tmux save-buffer "$file"
|
||||
tmux delete-buffer
|
||||
remove_empty_lines_from_end_of_file "$file"
|
||||
display_message "Scrollback saved to $file"
|
||||
}
|
||||
source $CURRENT_DIR/capture_pane_helpers.sh
|
||||
|
||||
main() {
|
||||
scrollback_dump
|
||||
local file="$(get_path)/$(get_filename)"
|
||||
capture_pane "Scrollback" "$file"
|
||||
}
|
||||
main
|
||||
|
|
|
|||
Loading…
Reference in a new issue