From 0a24f23d50325d6c109160cecfdc9e1cfc251beb Mon Sep 17 00:00:00 2001 From: Bruce Edge Date: Sat, 25 May 2019 08:35:10 -0700 Subject: [PATCH 1/5] Let start_logging be called directly. --- scripts/start_logging.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/start_logging.sh b/scripts/start_logging.sh index 3841b3c..ae345d9 100755 --- a/scripts/start_logging.sh +++ b/scripts/start_logging.sh @@ -3,6 +3,17 @@ # path to log file - global variable FILE="$1" +# If called directly, read context and enable logging +if [ ! "${FILE}" ] ; then + CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + + source "$CURRENT_DIR/variables.sh" + source "$CURRENT_DIR/shared.sh" + file=$(expand_tmux_format_path "${logging_full_filename}") + display_message "Started logging to ${logging_full_filename}" + +fi + ansifilter_installed() { type ansifilter >/dev/null 2>&1 || return 1 } @@ -18,12 +29,14 @@ pipe_pane_ansifilter() { pipe_pane_sed_osx() { # 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:]]+$)" + 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 ansi_codes="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]| )" + 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" } From cd79053b51f0e38c263fad78b0a5677c17462850 Mon Sep 17 00:00:00 2001 From: Bruce Edge Date: Sat, 25 May 2019 09:51:48 -0700 Subject: [PATCH 2/5] New script to snapshot scrillback AND enable logging to same file. --- scripts/snapshot_and_log.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 scripts/snapshot_and_log.sh diff --git a/scripts/snapshot_and_log.sh b/scripts/snapshot_and_log.sh new file mode 100755 index 0000000..ae17f9b --- /dev/null +++ b/scripts/snapshot_and_log.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/variables.sh" +source "$CURRENT_DIR/shared.sh" + +main() { + if supported_tmux_version_ok; then + local file=$(expand_tmux_format_path "${logging_full_filename}") + local history_limit="$(tmux display-message -p -F "#{history_limit}")" + tmux capture-pane -J -S "-${history_limit}" -p > "${file}" + remove_empty_lines_from_end_of_file "${file}" + "$CURRENT_DIR/start_logging.sh" "${file}" + + display_message "History saved and logging started to ${file}" + fi +} +main From 3a9be4926c8f410597d9b150f7cde02eed3cde71 Mon Sep 17 00:00:00 2001 From: Bruce Edge Date: Sat, 25 May 2019 10:15:47 -0700 Subject: [PATCH 3/5] Add docs & default key binding for snapshot_and_log. --- README.md | 10 ++++++++++ logging.tmux | 1 + scripts/variables.sh | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a0b8f40..98c2297 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,16 @@ you need to log/save all the work. * File path: `$HOME` (user home dir) * Example file: `tmux-history-my-session-0-1-20140527T165614.log` +### 4. Save complete history and continue logging to same file + +Save complete pane history to a file then continue logging to it. Convenient if you retroactively remember you need to log/save all the work, including what follows. + +* Key binding: `prefix + ctrl + shift + p` +* File name format: `tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log` +* File path: `$HOME` (user home dir) + * Example file: `~/tmux-my-session-0-1-20140527T165614.log` + + **NOTE**: this functionality depends on the value of `history-limit` - the number of lines Tmux keeps in the scrollback buffer. Only what Tmux kept will also be saved, to a file. diff --git a/logging.tmux b/logging.tmux index c65856e..e3991fb 100755 --- a/logging.tmux +++ b/logging.tmux @@ -11,6 +11,7 @@ main() { tmux bind-key "$pane_screen_capture_key" run-shell "$CURRENT_DIR/scripts/screen_capture.sh" tmux bind-key "$save_complete_history_key" run-shell "$CURRENT_DIR/scripts/save_complete_history.sh" tmux bind-key "$clear_history_key" run-shell "$CURRENT_DIR/scripts/clear_history.sh" + tmux bind-key "$snapshot_and_log_key" run-shell "$CURRENT_DIR/scripts/snapshot_and_log.sh" } main diff --git a/scripts/variables.sh b/scripts/variables.sh index a27c24f..3ba59c8 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -14,6 +14,10 @@ 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} +default_snapshot_and_log_key="C-P" # Control-Alt-Shift-p +snapshot_and_log_key=$(tmux show-option -gqv "@snapshot_and_log") +snapshot_and_log_key=${snapshot_and_log_key:-$default_snapshot_and_log_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} From 58f135fc347a499449220f201410cf263d85e6da Mon Sep 17 00:00:00 2001 From: Bruce Edge Date: Sat, 25 May 2019 10:20:30 -0700 Subject: [PATCH 4/5] Fix typos in docs. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98c2297..1ca9d55 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,13 @@ you need to log/save all the work. Save complete pane history to a file then continue logging to it. Convenient if you retroactively remember you need to log/save all the work, including what follows. -* Key binding: `prefix + ctrl + shift + p` +* Key binding: `prefix + ctrl + P` * File name format: `tmux-#{session_name}-#{window_index}-#{pane_index}-%Y%m%dT%H%M%S.log` * File path: `$HOME` (user home dir) * Example file: `~/tmux-my-session-0-1-20140527T165614.log` -**NOTE**: this functionality depends on the value of `history-limit` - the number +**NOTE**: the last 2 features functionality depends on the value of `history-limit` - the number of lines Tmux keeps in the scrollback buffer. Only what Tmux kept will also be saved, to a file. From 61e471ea71dd583b1bf47fd0794caaf61f98e1d5 Mon Sep 17 00:00:00 2001 From: Bruce Edge Date: Sat, 25 May 2019 10:21:59 -0700 Subject: [PATCH 5/5] Fix more typos in docs. --- scripts/variables.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/variables.sh b/scripts/variables.sh index 3ba59c8..c9376a9 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -14,7 +14,7 @@ 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} -default_snapshot_and_log_key="C-P" # Control-Alt-Shift-p +default_snapshot_and_log_key="C-P" # Control-Shift-p snapshot_and_log_key=$(tmux show-option -gqv "@snapshot_and_log") snapshot_and_log_key=${snapshot_and_log_key:-$default_snapshot_and_log_key}