From b7a4ee2a40765ba23a25544211024c35e5025620 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 30 May 2017 06:40:48 +0200 Subject: [PATCH] Pane contents save and restore in separate dirs --- scripts/helpers.sh | 18 ++++++++---------- scripts/restore.sh | 4 ++-- scripts/save.sh | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index e5abf6e..0d40b6d 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -78,22 +78,19 @@ is_session_grouped() { # pane content file helpers pane_contents_create_archive() { - tar cf - -C "$(resurrect_dir)" ./pane_contents/ | + tar cf - -C "$(resurrect_dir)/save/" ./pane_contents/ | gzip > "$(pane_contents_archive_file)" } pane_content_files_restore_from_archive() { local archive_file="$(pane_contents_archive_file)" if [ -f "$archive_file" ]; then + mkdir -p "$(pane_contents_dir "restore")" gzip -d < "$archive_file" | - tar xf - -C "$(resurrect_dir)" + tar xf - -C "$(resurrect_dir)/restore/" fi } -pane_content_files_cleanup() { - rm "$(pane_contents_dir)"/* -} - # path helpers resurrect_dir() { @@ -111,17 +108,18 @@ last_resurrect_file() { } pane_contents_dir() { - echo "$(resurrect_dir)/pane_contents/" + echo "$(resurrect_dir)/$1/pane_contents/" } pane_contents_file() { - local pane_id="$1" - echo "$(pane_contents_dir)/pane-${pane_id}" + local save_or_restore="$1" + local pane_id="$2" + echo "$(pane_contents_dir "$save_or_restore")/pane-${pane_id}" } pane_contents_file_exists() { local pane_id="$1" - [ -f "$(pane_contents_file "$pane_id")" ] + [ -f "$(pane_contents_file "restore" "$pane_id")" ] } pane_contents_archive_file() { diff --git a/scripts/restore.sh b/scripts/restore.sh index 4f949c8..8e9c550 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -108,7 +108,7 @@ tmux_default_command() { } pane_creation_command() { - echo "cat '$(pane_contents_file "${1}:${2}.${3}")'; exec $(tmux_default_command)" + echo "cat '$(pane_contents_file "restore" "${1}:${2}.${3}")'; exec $(tmux_default_command)" } new_window() { @@ -259,7 +259,7 @@ restore_all_panes() { fi done < $(last_resurrect_file) if is_restoring_pane_contents; then - pane_content_files_cleanup + rm "$(pane_contents_dir "restore")"/* fi } diff --git a/scripts/save.sh b/scripts/save.sh index a58ebd4..97ccd8b 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -138,7 +138,7 @@ capture_pane_contents() { start_line="0" fi # the printf hack below removes *trailing* empty lines - printf '%s\n' "$(tmux capture-pane -epJ -S "$start_line" -t "$pane_id")" > "$(pane_contents_file "$pane_id")" + printf '%s\n' "$(tmux capture-pane -epJ -S "$start_line" -t "$pane_id")" > "$(pane_contents_file "save" "$pane_id")" fi } @@ -266,10 +266,10 @@ save_all() { rm "$resurrect_file_path" fi if capture_pane_contents_option_on; then - mkdir -p "$(pane_contents_dir)" + mkdir -p "$(pane_contents_dir "save")" dump_pane_contents pane_contents_create_archive - pane_content_files_cleanup + rm "$(pane_contents_dir "save")"/* fi if save_bash_history_option_on; then dump_bash_history