mirror of
https://github.com/tmux-plugins/tmux-logging.git
synced 2026-09-10 07:16:28 -04:00
Refactoring proper-pipe-pane functionality
This commit is contained in:
parent
9d97719c47
commit
1421d5b506
|
|
@ -4,28 +4,28 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
|
||||
source $CURRENT_DIR/scripts/shared.sh
|
||||
|
||||
default_pipe_pane_key="P"
|
||||
default_pipe_pane_key="P" # Shift-p
|
||||
default_pane_screenshot_key="M-p" # Alt-p
|
||||
default_pane_scrollback_key="M-P" # Alt-Shift-p
|
||||
default_scrollback_dump_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")
|
||||
tmux bind-key "$pipe_pane_key" run-shell "$CURRENT_DIR/scripts/tmux_proper_pipe_pane.sh"
|
||||
local key=$(get_tmux_option "@pipe_pane_key" "$default_pipe_pane_key")
|
||||
tmux bind-key "$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"
|
||||
local key=$(get_tmux_option "@pane_screenshot_key" "$default_pane_screenshot_key")
|
||||
tmux bind-key "$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"
|
||||
setup_scrollback_dump_key_binding() {
|
||||
local key=$(get_tmux_option "@scrollback_dump_key" "$default_scrollback_dump_key")
|
||||
tmux bind-key "$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
|
||||
setup_scrollback_dump_key_binding
|
||||
}
|
||||
main
|
||||
|
|
|
|||
|
|
@ -5,45 +5,29 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
default_log_path="$HOME"
|
||||
default_log_name="tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
|
||||
|
||||
log_path_option="@pipe_pane_path"
|
||||
log_name_option="@pipe_pane_filename"
|
||||
|
||||
source $CURRENT_DIR/shared.sh
|
||||
|
||||
get_log_path() {
|
||||
get_tmux_option "@ppp_path" "$default_log_path"
|
||||
get_tmux_option "$log_path_option" "$default_log_path"
|
||||
}
|
||||
|
||||
get_log_name() {
|
||||
get_tmux_option "@ppp_name" "$default_log_name"
|
||||
}
|
||||
|
||||
ansifilter_installed() {
|
||||
type ansifilter >/dev/null 2>&1 || return 1
|
||||
}
|
||||
|
||||
system_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
get_tmux_option "$log_name_option" "$default_log_name"
|
||||
}
|
||||
|
||||
start_pipe_pane() {
|
||||
local log_path=$(get_log_path)
|
||||
local log_name=$(get_log_name)
|
||||
if ansifilter_installed; then
|
||||
tmux pipe-pane "exec cat - | ansifilter >> $log_path/$log_name"
|
||||
elif system_osx; then
|
||||
# OSX uses sed '-E' flag and a slightly different regex
|
||||
# Warning, very complex regex ahead.
|
||||
# Some characters below might not be wisible from github web view.
|
||||
tmux pipe-pane "exec cat - | sed -E \"s/(\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]|
|]0;[^]+|[[:space:]]+$)//g\" >> $log_path/$log_name"
|
||||
else
|
||||
tmux pipe-pane "exec cat - | sed -r 's/(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]|
)//g' >> $log_path/$log_name"
|
||||
fi
|
||||
display_message "Started logging to $log_path/$log_name"
|
||||
local file="$(get_log_path)/$(get_log_name)"
|
||||
$CURRENT_DIR/tmux_start_pipe_pane.sh "$file"
|
||||
display_message "Started logging to $file"
|
||||
}
|
||||
|
||||
stop_pipe_pane() {
|
||||
local log_path=$(get_log_path)
|
||||
local log_name=$(get_log_name)
|
||||
local file="$(get_log_path)/$(get_log_name)"
|
||||
tmux pipe-pane
|
||||
display_message "Ended logging to $log_path/$log_name"
|
||||
display_message "Ended logging to $file"
|
||||
}
|
||||
|
||||
# returns a string unique to current pane
|
||||
|
|
@ -51,6 +35,7 @@ pane_unique_id() {
|
|||
tmux display-message -p "#{session_name}_#{window_index}_#{pane_index}"
|
||||
}
|
||||
|
||||
# saving 'logging' 'not logging' status in a variable unique to pane
|
||||
set_logging_variable() {
|
||||
local value=$1
|
||||
local pane_unique_id="$(pane_unique_id)"
|
||||
|
|
|
|||
49
scripts/tmux_start_pipe_pane.sh
Executable file
49
scripts/tmux_start_pipe_pane.sh
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# path to log file
|
||||
file=$1
|
||||
|
||||
ansifilter_installed() {
|
||||
type ansifilter >/dev/null 2>&1 || return 1
|
||||
}
|
||||
|
||||
system_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
pipe_pane_ansifilter() {
|
||||
local file=$1
|
||||
tmux pipe-pane "exec cat - | ansifilter >> $file"
|
||||
}
|
||||
|
||||
pipe_pane_sed_osx() {
|
||||
local file=$1
|
||||
# Warning, very complex regex ahead.
|
||||
# Some characters below might not be visible from github web view.
|
||||
local ansi_codes_osx="(\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]|
|]0;[^]+|[[:space:]]+$)"
|
||||
tmux pipe-pane "exec cat - | sed -E \"s/$ansi_codes_osx//g\" >> $file"
|
||||
}
|
||||
|
||||
pipe_pane_sed() {
|
||||
local file=$1
|
||||
local ansi_codes="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]|
)"
|
||||
tmux pipe-pane "exec cat - | sed -r 's/$ansi_codes//g' >> $file"
|
||||
}
|
||||
|
||||
start_pipe_pane() {
|
||||
local file=$1
|
||||
if ansifilter_installed; then
|
||||
pipe_pane_ansifilter "$file"
|
||||
elif system_osx; then
|
||||
# OSX uses sed '-E' flag and a slightly different regex
|
||||
pipe_pane_sed_osx "$file"
|
||||
else
|
||||
pipe_pane_sed "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local file=$1
|
||||
start_pipe_pane "$file"
|
||||
}
|
||||
main "$file"
|
||||
Loading…
Reference in a new issue