Unverified Commit b7a4ee2a authored by Bruno Sutic's avatar Bruno Sutic
Browse files

Pane contents save and restore in separate dirs

parent ba59a2b6
......@@ -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() {
......
......@@ -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
}
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment