mirror of
https://github.com/tmux-plugins/tmux-logging.git
synced 2026-09-10 07:16:28 -04:00
Add pane screenshot functionality
This commit is contained in:
parent
f4d4a49adf
commit
180815614b
|
|
@ -1,26 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This plugin extends basic tmux pipe-pane (a.k.a. logging) functionality
|
||||
# nicely described here: http://unix.stackexchange.com/a/10259
|
||||
# Improvements:
|
||||
# 1. uses `ansifilter` (if it's installed) to clean out unreadable ANSI codes
|
||||
# from the pipe-pane log
|
||||
# 2. *one* key is used to toggle tmux `pipe-pane`. That is usually possible
|
||||
# when `pipe-pane -o` is used, but then you can't get a descriptive log
|
||||
# message. Basically, you don't know if logging started or it just ended.
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source $CURRENT_DIR/scripts/shared.sh
|
||||
|
||||
default_ppp_key="P"
|
||||
default_pipe_pane_key="P"
|
||||
default_pane_screenshot_key="M-p" # Alt-p
|
||||
|
||||
setup_key_binding() {
|
||||
local ppp_key=$(get_tmux_option "@ppp_key" "$default_ppp_key")
|
||||
tmux bind-key "$ppp_key" run-shell "$CURRENT_DIR/scripts/tmux_proper_pipe_pane.sh"
|
||||
setup_pipe_pane_key_binding() {
|
||||
local pipe_pane_key=$(get_tmux_option "@ppp_pipe_pane_key" "$default_pipe_pane_key")
|
||||
tmux bind-key "$pipe_pane_key" run-shell "$CURRENT_DIR/scripts/tmux_proper_pipe_pane.sh"
|
||||
}
|
||||
|
||||
setup_pane_screenshot_key_binding() {
|
||||
local pane_screenshot_key=$(get_tmux_option "@ppp_pane_screenshot_key" "$default_pane_screenshot_key")
|
||||
tmux bind-key "$pane_screenshot_key" run-shell "$CURRENT_DIR/scripts/tmux_pane_screenshot.sh"
|
||||
}
|
||||
|
||||
main() {
|
||||
setup_key_binding
|
||||
setup_pipe_pane_key_binding
|
||||
setup_pane_screenshot_key_binding
|
||||
}
|
||||
main
|
||||
|
|
|
|||
33
scripts/tmux_pane_screenshot.sh
Executable file
33
scripts/tmux_pane_screenshot.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
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"
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
main() {
|
||||
pane_screenshot
|
||||
}
|
||||
main
|
||||
Loading…
Reference in a new issue