My bash-fu is laughable and this took me days (yes, days!) to put together, so hope it helps.
fswatch which you should have installed and is supposedly cross-platform, but I've only tested it on MacOS (
brew install fswatch).
Dotfile Dropbox git auto-committer
This is my use case:
- I keep my dotfiles in multiple git repos under
- I symlink them to wherever they need to be.
- I want to edit a file, and, as soon as I save it, have it be added and commited to its repo.
Naming things is hard, and so is "naming" file changes as commit messages. Often I take a piece of bash config from StackOverflow, and I paste the link to the answer as a comment in the file itself, so it'd be redundant to justify the change in a commit message.
Most of all, I don't want to carefully organize my commits for these things, just have a way to undo screw-ups.
- Create a file (let's say,
paths.txt) with one path per line of repositories you want to watch and auto-commit.
- Make sure
git-commit-unattended.share in your PATH. I symlink them to
git-watch.sh < /path/to/paths.txt.
Other use cases
Of course you can use this to track changes to any directory, not only one with dotfiles. I also add
~/Dropbox/org to my
paths.txt file to keep track of changes to my org-mode files, for instance. It's a life-saver.
This is also not exclusive to Dropbox. It could be a mounted remote filesystem (who uses that?) or a local git repo with a post-commit-hook that pushes it to a remote.
Starting automatically on login
I'm still trying to figure out how to use
launchd on MacOS to start this automatically, but it is proving harder than I thought
Starting it yourself by calling
git-watch-my-paths-on-login.sh works though, so if that's good enough for you, you've got a watcher already!
If this helped you, I'd love to know about it. Makes me want to share more stuff I patch together for myself. A star on the gist or a fave/RT on Twitter means the world to me