Create backup of each edited file

Why?

I wrote this plugin after having lost a few hours re-writing a file I had deleted by accident (yes I was in a git repo, but I ran git clean -f by accident - it happens)

I thought about several solutions and came up with this one, that you may find interesting.

Usage

  • Download kak-back from my dotfiles repo - it’s a standalone Python3 script.
  • Make it executable and put it somewhere in your PATH
  • Call kak-back backup in a WritePost hook:
hook global BufWritePost .* %{ 
  nop %sh{ kak-back backup  "${kak_hook_param}" } 
}
  • Restore a deleted file with : kak-back restore PATH

Remember to run kak-back clean from time to time, otherwise ~/.local/share/kak/backups will grow indefinitely.

If you find this interesting, I may take the time to convert it to a proper kak plugin instead - but in its current form it’s easier to tweak should you have to.

Cheers!

Quick link to Default hooks.

hook global KakEnd .* %{
 nop %sh{ kak-back clean }
}

As the clean function checks if now - mtime > ONE_MONTH

Cool stuff, going to try it out. Thanks.


Had a play and:

  • the obligatory user knows best: ONE_MONTH into command line flag
  • for easier rollback on incremental saves of the same file a date-time suffix: 2020-05-16-12:27:14.509998
  • changed directory share/kak to share/kak-back inline with your share/kak-spell
  • just a couple of tests for kak-back clean and all good.

$ cat kak-back.py > kak-back && chmod u+x,u-w,og-rwx kak-back && mv kak-back ~/local/bin/

And cool, cool, do your thing.


would also be nice if it had a command line flag --ignore-dot for private dot files.