Pane contents save and restore in separate dirs

This commit is contained in:
Bruno Sutic 2017-05-30 06:40:48 +02:00
parent ba59a2b642
commit b7a4ee2a40
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
3 changed files with 13 additions and 15 deletions

View File

@ -78,22 +78,19 @@ is_session_grouped() {
# pane content file helpers # pane content file helpers
pane_contents_create_archive() { pane_contents_create_archive() {
tar cf - -C "$(resurrect_dir)" ./pane_contents/ | tar cf - -C "$(resurrect_dir)/save/" ./pane_contents/ |
gzip > "$(pane_contents_archive_file)" gzip > "$(pane_contents_archive_file)"
} }
pane_content_files_restore_from_archive() { pane_content_files_restore_from_archive() {
local archive_file="$(pane_contents_archive_file)" local archive_file="$(pane_contents_archive_file)"
if [ -f "$archive_file" ]; then if [ -f "$archive_file" ]; then
mkdir -p "$(pane_contents_dir "restore")"
gzip -d < "$archive_file" | gzip -d < "$archive_file" |
tar xf - -C "$(resurrect_dir)" tar xf - -C "$(resurrect_dir)/restore/"
fi fi
} }
pane_content_files_cleanup() {
rm "$(pane_contents_dir)"/*
}
# path helpers # path helpers
resurrect_dir() { resurrect_dir() {
@ -111,17 +108,18 @@ last_resurrect_file() {
} }
pane_contents_dir() { pane_contents_dir() {
echo "$(resurrect_dir)/pane_contents/" echo "$(resurrect_dir)/$1/pane_contents/"
} }
pane_contents_file() { pane_contents_file() {
local pane_id="$1" local save_or_restore="$1"
echo "$(pane_contents_dir)/pane-${pane_id}" local pane_id="$2"
echo "$(pane_contents_dir "$save_or_restore")/pane-${pane_id}"
} }
pane_contents_file_exists() { pane_contents_file_exists() {
local pane_id="$1" local pane_id="$1"
[ -f "$(pane_contents_file "$pane_id")" ] [ -f "$(pane_contents_file "restore" "$pane_id")" ]
} }
pane_contents_archive_file() { pane_contents_archive_file() {

View File

@ -108,7 +108,7 @@ tmux_default_command() {
} }
pane_creation_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() { new_window() {
@ -259,7 +259,7 @@ restore_all_panes() {
fi fi
done < $(last_resurrect_file) done < $(last_resurrect_file)
if is_restoring_pane_contents; then if is_restoring_pane_contents; then
pane_content_files_cleanup rm "$(pane_contents_dir "restore")"/*
fi fi
} }

View File

@ -138,7 +138,7 @@ capture_pane_contents() {
start_line="0" start_line="0"
fi fi
# the printf hack below removes *trailing* empty lines # 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 fi
} }
@ -266,10 +266,10 @@ save_all() {
rm "$resurrect_file_path" rm "$resurrect_file_path"
fi fi
if capture_pane_contents_option_on; then if capture_pane_contents_option_on; then
mkdir -p "$(pane_contents_dir)" mkdir -p "$(pane_contents_dir "save")"
dump_pane_contents dump_pane_contents
pane_contents_create_archive pane_contents_create_archive
pane_content_files_cleanup rm "$(pane_contents_dir "save")"/*
fi fi
if save_bash_history_option_on; then if save_bash_history_option_on; then
dump_bash_history dump_bash_history