Skip to content

Instantly share code, notes, and snippets.

@stavxyz
Last active December 13, 2022 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stavxyz/522fa68b581b241f9616b4482201dadc to your computer and use it in GitHub Desktop.
Save stavxyz/522fa68b581b241f9616b4482201dadc to your computer and use it in GitHub Desktop.
keeping files in sync over ssh for modern humans

the problem

  • I want to keep files instantaneously in-sync across two workstations
  • I want the solution to be platform-independent (mostly)
  • I want this to run in the foreground in a tmux pane so I can easily monitor
  • I want one simple command that I can re-use for any combination of target files/directories and destination directories
  • I want some control on how deletions are handled
  • Preferably, I won't have to mess with fsevents or inotify or maintaining additional scripts

https://github.com/facebook/watchman (specifically, watchman-make with --run) and an ssh connection makes this super easy.

brew install watchman

I want to continuously sync ~/do/project to do.stav.xyz:~/do/project:

export WROOT=do SHOST='do.stav.xyz' WATCHED_DIR='project' && \
  watchman-make --root $WROOT --pattern "$WATCHED_DIR"'/*' \
  --run "rsync --progress --links --update --delete-after --times \
  --inplace --recursive --verbose --executability \
  --rsh ssh $(realpath $WROOT/$WATCHED_DIR)/ "$SHOST:$WROOT/$WATCHED_DIR""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment