Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save scrollback and start logging as single function #39

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions logging.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions scripts/snapshot_and_log.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 15 additions & 2 deletions scripts/start_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
# path to log file - global variable
FILE="$1"

# If called directly, read context and enable logging
bedge marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand All @@ -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:]]+$)"
bedge marked this conversation as resolved.
Show resolved Hide resolved
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"
}

Expand Down
4 changes: 4 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down