Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

My bash-fu is laughable and this took me days (yes, days!) to put together, so hope it helps.

It uses 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 ~/Dropbox/dotfiles.
  • 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 and are in your PATH. I symlink them to ~/usr/bin/.
  • Call < /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😓. You'll find below my current (non-working) .plist file.

Starting it yourself by calling works though, so if that's good enough for you, you've got a watcher already!

Saying thanks

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 😊

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
cd "$1" && git add . && git commit -m "unattended"
# Exporting PATH here is because launchd doesn't pick it up from .bash_profile/.bashrc.
# Change these two paths below with the path where you added ``
# and `` and the one where you keep the paths of repositories you want to
# watch.
export PATH="$HOME/usr/bin:$PATH" < /Users/kbdluv/Dropbox/dotfiles/git-watch-paths.txt
# PATH for launchd to find `fswatch`
export PATH="/usr/local/bin:$PATH"
while read -r line; do
fswatch -r "$line" | grep --line-buffered -v '.git' | xargs -n1 -I{} "$line";
} &

This comment has been minimized.

Copy link

glassdimly commented Jul 4, 2018

Very helpful, thanks! I was trying to modify to work on mac, but it's a little over-complicated.


This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.