Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an 'initial_only' setting to restrict on-open backups to first one #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Automatic Backups.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// If true, also save a backup copy any time a file is opened
"backup_on_open_file": false,
"backup_on_open__initial_only": false,

// External command to execute when Merge command is used (Ctrl+Alt+Shift+M by default).
"backup_merge_command": ""
Expand Down
12 changes: 11 additions & 1 deletion AutomaticBackups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ def on_activated(self, view):

def on_load(self, view):
"""When a file is opened, put a copy of the file into the
backup directory if backup_on_open_file setting is true."""
backup directory if backup_on_open_file setting is true. Optionally,
only perform backup on open initially (ie no backups yet exists) by
setting backup_on_open__initial_only to true."""

settings = get_settings()

if settings.get('backup_on_open_file', False):
if settings.get('backup_on_open__initial_only', False):
nav.find_backups(view)
if nav.found_backup_files:
print ("Backup not saved, 'backup_on_open__initial_only' is"
" true and a backup already exists.")
return
self.save_view_to_backup(view)

def save_view_to_backup(self, view):
Expand Down