Table of Contents
Snapshot-timemachine provides a polished interface to step through the snapshots of a file made by a third-party snapshot or backup facility, e.g. Btrfs, ZFS, etc.
Out of the box, it can detect snapshots made by Snapper and automatic ZFS
snapshots (snapshot names start with zfs-auto-snap), but it provides a simple
interface to add support for other snapshot facilities.
It provides two views: the timemachine and the timeline.
Invoke with M-x snapshot-timemachine. Inspired by git-timemachine. Opens
a new buffer viewing the current snapshot of the visited file. You can easily
go back and forth in time and view the state of the file in the snapshots you
made.
Available bindings:
nShow the next snapshotpShow the previous snapshotNShow the next snapshot that differs from the current onePShow the previous snapshot that differs from the current one<Show the first recorded snapshot>Show the last (current) recorded snapshotjPick a snapshot to showtorlActivate the timelineqQuitrRestore the file to the shown snapshotsSave the shown snapshot as a new file
Invoke with M-x snapshot-timeline. Opens a new buffer listing all the
snapshots made of the visited file. The Diffstat column indicates the changes
between snapshots. You can step through the list, view snapshots, open diffs,
revert a snapshot, etc. You can mark two snapshots as A and B to quickly
compare them or to start an ediff or emerge session using them.
Available bindings:
RETShow the selected snapshot in the timemachine or the diff when the point is on a diffstatSPCorvShow the selected snapshot in the timemachine in another window=Show the diff between the previous snapshot and the selected onerRestore the file to the shown snapshotqQuitnShow the next snapshotpShow the previous snapshotNShow the next snapshot that differs from the current onePShow the previous snapshot that differs from the current one<Show the first recorded snapshot>Show the last (current) recorded snapshotiOnly show snapshots with changes (toggle)aMark the selected snapshot as AbMark the selected snapshot as BuUnmark the current snapshotUUnmark all snapshotsdShow the diff between snapshots A and BeStart anediffsession with snapshots A and BmStart anemergesession with snapshots A and B
-
Manual install:
(add-to-list 'load-path "/path/to/snapshot-timemachine") (require 'snapshot-timemachine)
There are a couple of options that can be tweaked:
snapshot-timemachine-snapshot-finder(default:#'snapshot-timemachine-snapper-snapshot-finder) the function used to retrieve the snapshots for a given file.snapshot-timemachine-time-format(default:"%a %d %b %Y %R") the format used to display the dates.snapshot-timemachine-diff-switches(default:"-u") the switches to pass todiffwhen calculating a diff between snapshots.snapshot-timemachine-include-current(default:t) include the current state of the file in the timeline and timemachine.snapshot-timemachine-sync-with-timeline(default:t) when scrolling through the timeline, show the selected snapshot in the timemachine when active. If for some reason loading a snapshot takes a while (e.g. stored on remote storage), setting this tonilwill make moving around in the timeline more responsive.snapshot-timemachine-name-column-width(default:30) width to use for the snapshot name column in the timeline.
To use snapshot-timemachine for a snapshot system not supported out of the
box, you have to define your own function to find the snapshots.
Given an absolute path to a file as only argument, the function must return a
list of snapshot structs of the existing snapshots of the file. When
snapshot-timemachine-include-current is t, the current version of the file
will be added to this list for you, so you don't have to include it.
The snapshot struct has the following slots:
-
idAn ascending numerical identifier for internal lookups. Users will not see this, so you can just generate this. -
nameThe name of the snapshot that will be displayed in the timemachine and the timeline. -
fileThe absolute path to the snapshotted file, e.g."/home/.snapshots/2/snapshot/thomas/.emacs.d/init.el". -
dateThe date/time at which the snapshot was made, format:(HIGH LOW USEC PSEC), a standard Emacs time object. -
diffstatThe number of lines added/removed compared to the previous snapshot, format:(ADDED . REMOVED). You can leave thisnil, it will be calculated for you.
When you have defined your function, store it in the variable
snapshot-timemachine-snapshot-finder. That's it!
You can have a look at snapshot-timemachine-snapper-snapshot-finder for
inspiration.
Distributed under the GNU General Public License.

