Create new file only if there are changes

Code submitted by @vburdo in
https://github.com/tmux-plugins/tmux-resurrect/issues/156
pull/510/head
Bruno Sutic 2017-05-30 05:14:14 +02:00
parent dec4e15fc5
commit b1f3df21e9
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
3 changed files with 11 additions and 1 deletions

View File

@ -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"

View File

@ -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" ]

View File

@ -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