diff --git a/README.md b/README.md index a0b8f40..1ca9d55 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,17 @@ you need to log/save all the work. * File path: `$HOME` (user home dir) * Example file: `tmux-history-my-session-0-1-20140527T165614.log` -**NOTE**: this functionality depends on the value of `history-limit` - the number +### 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 + 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**: 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. 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/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 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" } diff --git a/scripts/variables.sh b/scripts/variables.sh index a27c24f..c9376a9 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-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}