From a697b40255ed7acb7ebf467e892501ce5cc5de52 Mon Sep 17 00:00:00 2001 From: michael_coleman Date: Sat, 28 Nov 2015 01:05:50 +1300 Subject: [PATCH 1/3] added option: delete old continuum saves --- scripts/continuum_save.sh | 10 ++++++++++ scripts/variables.sh | 1 + 2 files changed, 11 insertions(+) diff --git a/scripts/continuum_save.sh b/scripts/continuum_save.sh index c85f68a..cf61ebf 100755 --- a/scripts/continuum_save.sh +++ b/scripts/continuum_save.sh @@ -34,9 +34,19 @@ fetch_and_run_tmux_resurrect_save_script() { fi } +delete_old_saves() { + ls ${HOME}/.tmux/resurrect/* -1dtr | head -n -10 | xargs -d '\n' rm -f +} + main() { if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then fetch_and_run_tmux_resurrect_save_script fi + + # if user has enabled @continuum-delete-old-saves-option 'on' + if [ -n $(get_tmux_option "$delete_old_saves_option" "") ] + then + delete_old_saves + fi } main diff --git a/scripts/variables.sh b/scripts/variables.sh index 1ddda9e..89709f8 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -6,6 +6,7 @@ resurrect_restore_path_option="@resurrect-restore-script-path" auto_save_interval_option="@continuum-save-interval" auto_save_interval_default="15" +delete_old_saves_option="@continuum-delete-old-saves-option" # time when the tmux environment was last saved (unix timestamp) last_auto_save_option="@continuum-save-last-timestamp" From f17fc076af7cb677c6a70961f1fc564cb2d162f0 Mon Sep 17 00:00:00 2001 From: michael_coleman Date: Thu, 3 Dec 2015 04:01:33 +1300 Subject: [PATCH 2/3] replaced ls with find command, use @resurrect dir,run del every 15mins --- scripts/continuum_save.sh | 21 ++++++++++++++------- scripts/helpers.sh | 5 +++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/continuum_save.sh b/scripts/continuum_save.sh index cf61ebf..6471483 100755 --- a/scripts/continuum_save.sh +++ b/scripts/continuum_save.sh @@ -34,19 +34,26 @@ fetch_and_run_tmux_resurrect_save_script() { fi } +resurrect_dir() { + local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" + echo "${path/#\~/$HOME}" # expands tilde if used with @resurrect-dir +} + delete_old_saves() { - ls ${HOME}/.tmux/resurrect/* -1dtr | head -n -10 | xargs -d '\n' rm -f + # check if @resurrect-dir was set - if so use it + local resurrect_save_dir=$(resurrect_dir) + find $resurrect_save_dir -type f -mtime +7 -name "tmux_resurrect_*.txt" -exec rm -f {} + } main() { if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then fetch_and_run_tmux_resurrect_save_script - fi - - # if user has enabled @continuum-delete-old-saves-option 'on' - if [ -n $(get_tmux_option "$delete_old_saves_option" "") ] - then - delete_old_saves + + # if user has enabled @continuum-delete-old-saves-option 'on' + if [ -n $(get_tmux_option "$delete_old_saves_option" "") ] + then + delete_old_saves + fi fi } main diff --git a/scripts/helpers.sh b/scripts/helpers.sh index b64fb36..d2fd484 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -1,3 +1,8 @@ +# these variables should possibly be in scripts/variables.sh +# but are currently here for consistency with tmux-resurrect +default_resurrect_dir="$HOME/.tmux/resurrect" +resurrect_dir_option="@resurrect-dir" + get_tmux_option() { local option="$1" local default_value="$2" From 0cb1c3462ccf807a66a4398fafea2c0b3548181f Mon Sep 17 00:00:00 2001 From: michael_coleman Date: Thu, 3 Dec 2015 05:18:27 +1300 Subject: [PATCH 3/3] made deleting saves older than 7 days the default --- scripts/continuum_save.sh | 4 ++-- scripts/variables.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/continuum_save.sh b/scripts/continuum_save.sh index 6471483..edc0e86 100755 --- a/scripts/continuum_save.sh +++ b/scripts/continuum_save.sh @@ -49,8 +49,8 @@ main() { if supported_tmux_version_ok && auto_save_not_disabled && enough_time_since_last_run_passed; then fetch_and_run_tmux_resurrect_save_script - # if user has enabled @continuum-delete-old-saves-option 'on' - if [ -n $(get_tmux_option "$delete_old_saves_option" "") ] + local keeping_old_saves=$(get_tmux_option "$keep_old_saves_option" "") + if [ -z "$keeping_old_saves" ] then delete_old_saves fi diff --git a/scripts/variables.sh b/scripts/variables.sh index 89709f8..59c6329 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -6,7 +6,7 @@ resurrect_restore_path_option="@resurrect-restore-script-path" auto_save_interval_option="@continuum-save-interval" auto_save_interval_default="15" -delete_old_saves_option="@continuum-delete-old-saves-option" +keep_old_saves_option="@continuum-keep-old-saves-option" # time when the tmux environment was last saved (unix timestamp) last_auto_save_option="@continuum-save-last-timestamp"