tmux-continuum
tmux-continuum copied to clipboard
added option: delete old continuum saves
Per the discussion on this issue this commit adds the functionality to delete old tmux-continuum saves.
This code doesn't change the default behaviour of continuum, but for those users who want to stop the ~/.tmux/resurrect
folder filling up with old save files, they can enable this by adding this line to ~/.tmux.conf
set -g @continuum-delete-old-saves-option 'on'
Note: the option uses this code provided by @gdebat, i.e.
ls ~/.tmux/resurrect/* -1dtr | head -n -10 | xargs -d '\n' rm -f
It retains the last 7 saves - but any additional saves beyond those 7 will be deleted.
Hey there! Thanks for contributing, we probably should provide a solution for deleting files.
I tested this locally and things exploded in a couple places:
-
head -n -10
blows up. Negative count unfortunately doesn't work on OSX -
ls ~/.tmux/resurrect/* -1dtr
also blows up. Command options need to go before the path pattern argument (on OSX at least).
If you agree let's make deleting old files the default (explicit option needed to disable that), but let's increase the number of files saved by default to last 7 days. We'll probably need to do a little math there: we wanna take the value of @continuum-save-interval
and figure how many files need to be saved to equal roughly 7 days.
Also, can we change ls ~/.tmux/resurrect/*
command to:
- take @resurrect-dir into account
- be more restrictive and "target only" files in resurrect dir having this format:
tmux_resurrect_*.txt
. There are options fortmux-resurrect
that save other file types in this dir and we never want to delete them.
Thanks!
Hey cool, I agree with
- making deleting old files the default
- take
@resurrect-dir
into account - using the pattern
tmux_resurrect_*.txt
to reduce likelyhood of mistakenly deleting the wrong files.
If we want to only delete files older than 7 days - which I think is a good idea - trying to determine the files age based on how many files are present multiplied by the file creation rate - will cause 2 problems that I can see
- From what I can tell tmux-contiuum only creates files when tmux is active
- If the save rate is changed e.g. from 15 mins to say 1minute
Fortunately this "older than 7 days test" is easy to achieve with
find $default_resurrect_dir -mtime +7
Where -mtime +7
is only files whose last modification time is older than 7 days.
Ive tested this command successfully on OSX yosemite (Using Sauce Labs) and I believe its quite POSIX compliant.
So I'm thinking the final command should look something like
find $default_resurrect_dir -type f -mtime +7 -name "tmux_resurrect_*.txt" -exec rm -f {} +
If that sounds good to you, I'll work it into the code and re-submit
Have now implemented the discussed changes.
These 2 commits make deleting saves older than 7 days the default behaviour for tmux-continuum.
If users want to keep files older than 7 days, they would need to add the following into ./tmux.conf
set -g @continuum-keep-old-saves-option 'on'
I have tested this as working on Ubuntu 14.04 for the following
- deleting files older than 7 days from the default
~/.tmux/resurrect
directory
Tested by creating dummy files and then setting modified date e.g.touch -t "1511220101" tmux_resurrect_2015-11-22T01:35:27.txt
. - deleting files when using a custom dir via
@resurrect-dir
e.g. set@resurrect-dir
to/tmp/resurrect_test
. - keeping old saves, i.e. not running the
delete_old_files
function when the@continuum-keep-old-saves-option 'on'
option is set.
Will this be merged? Is there anything else that needs to be addressed? I am willing to contribute.
@christarazi
Yes it would be nice if this got merged, I'm currently running the tmux-continuum
without this branch because its a bit too much hassle to clone from my repo then fetch and rebase onto new commits from the upstream master. Have you fetched this branch and tested the code? If so
- did it work?
- what OS are you running?
If we can get the code working across as many OS'es as possible, it might help to get it moving forward.
@michael-coleman
I will test it over the next few days. I will let you as soon as possible. I modified the command to delete files older than 1 day, so that I don't have to wait a week to get back to you on the results.
By the way, I am running Arch Linux.
Edit: @michael-coleman It works perfectly for me. The command I'm using is
$ find ~/.tmux/resurrect -type f -name "tmux_resurrect_*.txt" -mtime +0
which is basically deleting the resurrect files that are older than 24 hours.
@michael-coleman @bruno- How is this branch looking?
The FAQ seems to suggest that last
is a symlink.
One possible concern with the logic (as I understood by reading the comments here) is if I take a break from my computer (like that ever happens), and then go back after a week to open tmux, and since even my most recent save was more than 7 days ago, the file will be deleted, and I will have nothing to restore to. If last
is a hard link, then that issue shouldn't occur, I believe.
Hey guys, a similar PR was merged just yesterday to tmux-resurrect link. It deletes resurrect files older than 30 days but always keep at least 5 backups.
Can you check that one and close this PR if all the features are there?
@bruno- The one major difference I spotted was that this pull request has an option to enable deleting backups, while the other one does not. I think it would be more useful for people to have an option. I don't mind doing a pull request myself, just would like to hear your opinion before starting. Thanks.