From b1f3df21e9889e7324951e46be0249a5758dd9e1 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 30 May 2017 05:14:14 +0200 Subject: [PATCH] Create new file only if there are changes Code submitted by @vburdo in https://github.com/tmux-plugins/tmux-resurrect/issues/156 --- CHANGELOG.md | 1 + scripts/helpers.sh | 4 ++++ scripts/save.sh | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fb290..782c473 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - `mutt` added to the list of automatically restored programs - added guide for migrating from tmuxinator - fixed a bug for restoring commands on tmux 2.5 (and probably tmux 2.4) +- do not create another resurrect file if there are no changes (credit @vburdo) ### v2.4.0, 2015-02-23 - add "tmux-test" diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 6b7ea2e..e5abf6e 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -56,6 +56,10 @@ capture_pane_contents_option_on() { [ "$option" == "on" ] } +files_differ() { + ! cmp -s "$1" "$2" +} + save_bash_history_option_on() { local option="$(get_tmux_option "$bash_history_option" "off")" [ "$option" == "on" ] diff --git a/scripts/save.sh b/scripts/save.sh index 137e229..a58ebd4 100755 --- a/scripts/save.sh +++ b/scripts/save.sh @@ -254,12 +254,17 @@ dump_bash_history() { save_all() { local resurrect_file_path="$(resurrect_file_path)" + local last_resurrect_file="$(last_resurrect_file)" mkdir -p "$(resurrect_dir)" fetch_and_dump_grouped_sessions > "$resurrect_file_path" dump_panes >> "$resurrect_file_path" dump_windows >> "$resurrect_file_path" dump_state >> "$resurrect_file_path" - ln -fs "$(basename "$resurrect_file_path")" "$(last_resurrect_file)" + if files_differ "$resurrect_file_path" "$last_resurrect_file"; then + ln -fs "$(basename "$resurrect_file_path")" "$last_resurrect_file" + else + rm "$resurrect_file_path" + fi if capture_pane_contents_option_on; then mkdir -p "$(pane_contents_dir)" dump_pane_contents