I wrote code to a latex file for several hours without compiling nor manually saving, went for a break, my computer ran out of battery; once it was working again all progress had been lost. I want to avoid this in the future.
I have set my latex editor (texmaker) to regularly autosave, but I also want version control and remote backups, so I have the following script to automatically commit and push:
#!/bin/bash
if ps -ef | grep "texmaker report.tex" ; then
git commit -a -m "auto-commit progress on report"
git push origin master
exit 0
else
exit 0
fi
As you can see it will only commit if my specific treasured .tex document is being edited, rather than whenever a change has occured in the local repo.
To run this script automatically, I've got the following crontab set up:
0,10,20,30,40,50 * * * * ./autocommit.sh >/dev/null 2>&1
So far it's been working as planned, but it seems this approach might make some of you scream as I'll get meaningless commits. I'm willing to pay that price to avoid the incident, but is there another way to get regular backups with version control that avoids meaningless commits?