There a couple ways that you could do this:
- Bash/External tool
- Git-annex (all-in-one solution)
Which are all detailed here:
- If you want to do this in Vim:
Then I'd recommend using undo history, which not only (as it's name suggest) relate to the act of
undoing an action in the Vim editor, but also the one you save too. More here.
Adding the following to your
let vimDir = '$HOME/.vim'
" Keep undo history across sessions by storing it in a file
let myUndoDir = expand(vimDir . '/undodir')
" Create dirs
call system('mkdir ' . vimDir)
call system('mkdir ' . myUndoDir)
let &undodir = myUndoDir
Will make it so every changes/undo will be permanently kept under the directory
undodir under your local
vimDir, which is by default either
.vim in your home directory, or other ones mentioned in the output of
--version on the commandline.
For even more control over your undo history, I'd recommend also using Undotree to complement the experience.
- If you plan on doing this on Emacs:
There is a similar named packages called Undotree, which does similar things. More information on Undo history here.
- If you prefer a
I'd recommend using git-autocommit, which is a small bash script, with git as it's only dependencies, that watch the current git directory (where you launch it) for any new files/or modified files, and commit them.
Given the nature of
Git it keep every changes to the file, and while it wouldn't be suited for a production/serious project, it is a useful solution if you don't mind not having commit message/generic commit message (which you can always edit/add later on).
Launch it after navigating on the wanted git directory (which is first made with
git init on a specific directory, more info on the official manual) like so:
screen -dmS namehere git-autocommit -i 1 -V
if you're using
tmux new -n namehere git-autocommit -i 1 -V
git-autocommit -i 1 -V
will suffice if you prefer to not background it.
- If you prefer a
I'd recommend using
inotify-tools or more specifically
inotifywatch which can detect and (as it's name suggest) watch a file/directory for changes, which you can then do action on it (like save it somewhere else, etc).
Here the flag to use with
inotifywait -r -m -q -e close_write --format %w%f yourdirectorypathhere
and here an example
Bash script using the above:
inotifywait -r -m -q -e close_write --format %w%f directorytowatch | while IFS= read -r file; do
process can be anything you'd want, like
tar if you want to make backup on file modification, or with
rclone if you want to upload it somewhere...
- If you want a all-in-one solution:
git-annex which not only encompass
Git but many other external tools, like
More info on here.
If you feel like reading the wiki/forum later on, you can also git clone it locally, for offline reading:
git clone git://git-annex.branchable.com
for the website, forum (it's all in markdown, so it's very fast to download...), and codebase (it's in Haskell!) etc