mirror of
https://github.com/tmux-plugins/tmux-logging.git
synced 2026-09-10 07:16:28 -04:00
Changing variable working way. Reducing 'get_tmux_option' uses. Adding auto-creating folders in logging path
This commit is contained in:
parent
b2706119cd
commit
f5ed7640c8
13
logging.tmux
13
logging.tmux
|
|
@ -5,24 +5,21 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
source "$CURRENT_DIR/scripts/variables.sh"
|
||||
source "$CURRENT_DIR/scripts/shared.sh"
|
||||
|
||||
|
||||
setup_logging_key_binding() {
|
||||
local key="$(get_tmux_option "$logging_key_option" "$default_logging_key")"
|
||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
|
||||
tmux bind-key "$logging_key" run-shell "$CURRENT_DIR/scripts/toggle_logging.sh"
|
||||
}
|
||||
|
||||
setup_screen_capture_key_binding() {
|
||||
local key="$(get_tmux_option "$pane_screen_capture_key_option" "$default_pane_screen_capture_key")"
|
||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
|
||||
tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh"
|
||||
}
|
||||
|
||||
setup_save_complete_history_key_binding() {
|
||||
local key="$(get_tmux_option "$save_complete_history_key_option" "$default_save_complete_history_key")"
|
||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
|
||||
tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh"
|
||||
}
|
||||
|
||||
setup_clear_history_key_binding() {
|
||||
local key="$(get_tmux_option "$clear_history_key_option" "$default_clear_history_key")"
|
||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
|
||||
tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh"
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,15 @@
|
|||
# Variables in this helper should be 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 file="$(get_path)/$(get_filename)"
|
||||
local capture_scope=$1
|
||||
if [ $capture_scope == "History" ]; then
|
||||
local file=$(tmux display-message -p "$save_complete_history_full_filename")
|
||||
local path=$(tmux display-message -p "$save_complete_history_path")
|
||||
mkdir -p "$path"
|
||||
local history_limit="$(tmux display-message -p -F "#{history_limit}")"
|
||||
tmux capture-pane -J -S "-${history_limit}" -p > "$file"
|
||||
elif [[ $capture_scope == "Screen capture" ]]; then
|
||||
local file=$(tmux display-message -p "$screen_capture_full_filename")
|
||||
local path=$(tmux display-message -p "$screen_capture_path")
|
||||
mkdir -p "$path"
|
||||
tmux capture-pane -J -p > "$file"
|
||||
else
|
||||
# error
|
||||
|
|
|
|||
|
|
@ -6,13 +6,6 @@ source "$CURRENT_DIR/variables.sh"
|
|||
source "$CURRENT_DIR/shared.sh"
|
||||
source "$CURRENT_DIR/capture_pane_helpers.sh"
|
||||
|
||||
# Functions defined in capture_pane_helpers are customized via below variables.
|
||||
default_path="$default_save_complete_history_path"
|
||||
default_name="$default_save_complete_history_filename"
|
||||
|
||||
path_option="$save_complete_history_path_option"
|
||||
name_option="$save_complete_history_filename_option"
|
||||
|
||||
main() {
|
||||
if supported_tmux_version_ok; then
|
||||
capture_pane "History"
|
||||
|
|
|
|||
|
|
@ -6,13 +6,6 @@ source "$CURRENT_DIR/variables.sh"
|
|||
source "$CURRENT_DIR/shared.sh"
|
||||
source "$CURRENT_DIR/capture_pane_helpers.sh"
|
||||
|
||||
# Functions defined in capture_pane_helpers are customized via below variables.
|
||||
default_path="$default_screen_capture_path"
|
||||
default_name="$default_screen_capture_filename"
|
||||
|
||||
path_option="$screen_capture_path_option"
|
||||
name_option="$screen_capture_filename_option"
|
||||
|
||||
main() {
|
||||
if supported_tmux_version_ok; then
|
||||
capture_pane "Screen capture"
|
||||
|
|
|
|||
|
|
@ -5,21 +5,18 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|||
source "$CURRENT_DIR/variables.sh"
|
||||
source "$CURRENT_DIR/shared.sh"
|
||||
|
||||
get_filename() {
|
||||
local logging_path="$(get_tmux_option "$logging_path_option" "$default_logging_path")"
|
||||
local logging_filename="$(get_tmux_option "$logging_filename_option" "$default_logging_filename")"
|
||||
echo "${logging_path}/${logging_filename}"
|
||||
}
|
||||
|
||||
start_pipe_pane() {
|
||||
local filename="$(get_filename)"
|
||||
"$CURRENT_DIR/start_logging.sh" "$filename"
|
||||
display_message "Started logging to $filename"
|
||||
local file=$(tmux display-message -p "$logging_full_filename")
|
||||
local path=$(tmux display-message -p "$logging_path")
|
||||
mkdir -p "$path"
|
||||
"$CURRENT_DIR/start_logging.sh" "$file"
|
||||
display_message "Started logging to $logging_full_filename"
|
||||
}
|
||||
|
||||
stop_pipe_pane() {
|
||||
tmux pipe-pane
|
||||
display_message "Ended logging to $(get_filename)"
|
||||
display_message "Ended logging to $logging_full_filename"
|
||||
}
|
||||
|
||||
# returns a string unique to current pane
|
||||
|
|
|
|||
|
|
@ -2,38 +2,54 @@ SUPPORTED_VERSION="1.9"
|
|||
|
||||
# Key binding options and defaults
|
||||
|
||||
logging_key_option="@logging-key"
|
||||
default_logging_key="P" # Shift-p
|
||||
logging_key=$(tmux show-option -gqv "@logging_key")
|
||||
logging_key=${logging_key:-$default_logging_key}
|
||||
|
||||
pane_screen_capture_key_option="@screen-capture-key"
|
||||
default_pane_screen_capture_key="M-p" # Alt-p
|
||||
pane_screen_capture_key=$(tmux show-option -gqv "@screen-capture-key")
|
||||
pane_screen_capture_key=${pane_screen_capture_key:-$default_pane_screen_capture_key}
|
||||
|
||||
save_complete_history_key_option="@save-complete-history-key"
|
||||
default_save_complete_history_key="M-P" # Alt-Shift-p
|
||||
save_complete_history_key=$(tmux show-option -gqv "@save-complete-history-key")
|
||||
save_complete_history_key=${save_complete_history_key:-$default_save_complete_history_key}
|
||||
|
||||
clear_history_key_option="@clear-history-key"
|
||||
default_clear_history_key="M-c" # Alt-c
|
||||
clear_history_key=$(tmux show-option -gqv "@clear-history-key")
|
||||
clear_history_key=${clear_history_key:-$default_clear_history_key}
|
||||
|
||||
# General options
|
||||
filename_suffix="#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log"
|
||||
|
||||
# Logging options
|
||||
logging_path_option="@logging-path"
|
||||
default_logging_path="$HOME"
|
||||
logging_path=$(tmux show-option -gqv "@logging-path")
|
||||
logging_path=${logging_path:-$default_clear_history_key}
|
||||
|
||||
logging_filename_option="@logging-filename"
|
||||
default_logging_filename="tmux-${filename_suffix}"
|
||||
logging_filename=$(tmux show-option -gqv "@logging-filename")
|
||||
logging_filename=${logging_filename:-$default_logging_filename}
|
||||
|
||||
logging_full_filename="${logging_path}/${logging_filename}"
|
||||
|
||||
# Screen capture options
|
||||
screen_capture_path_option="@screen-capture-path"
|
||||
default_screen_capture_path="$HOME"
|
||||
screen_capture_path=$(tmux show-option -gqv "@screen-capture-path")
|
||||
screen_capture_path=${screen_capture_path:-$default_screen_capture_path}
|
||||
|
||||
screen_capture_filename_option="@screen-capture-filename"
|
||||
default_screen_capture_filename="tmux-screen-capture-${filename_suffix}"
|
||||
screen_capture_filename=$(tmux show-option -gqv "@screen-capture-filename")
|
||||
screen_capture_filename=${screen_capture_filename:-$default_screen_capture_filename}
|
||||
|
||||
screen_capture_full_filename="${screen_capture_path}/${screen_capture_filename}"
|
||||
|
||||
# Save complete history options
|
||||
save_complete_history_path_option="@save-complete-history-path"
|
||||
default_save_complete_history_path="$HOME"
|
||||
save_complete_history_path=$(tmux show-option -gqv "@save-complete-history-path")
|
||||
save_complete_history_path=${save_complete_history_path:-$default_save_complete_history_path}
|
||||
|
||||
save_complete_history_filename_option="@save-complete-history-filename"
|
||||
default_save_complete_history_filename="tmux-history-${filename_suffix}"
|
||||
save_complete_history_filename=$(tmux show-option -gqv "@save-complete-history-filename")
|
||||
save_complete_history_filename=${save_complete_history_filename:-$default_save_complete_history_filename}
|
||||
|
||||
save_complete_history_full_filename="${save_complete_history_path}/${save_complete_history_filename}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue