Sunday, May 10, 2020

rsync + fswatch for automated push to server

Like 90% of the work I do on my website, I do using a homebrew in-browser editor system (backed by PHP) I made by wrapping "Ace". It's super-convenient to be able to edit any file on any of my sites but it is ultimately limiting: I've been too reluctant to set up a build system, and so would only use technology stacks that were basically scripted, and thus the gap between my coding style at work and my coding style for fun was widening.

Baby steps would be setting up automatic file synching between my laptop and my server - plus I've really started liking VSCode's prettify module, everything just feels so professional when it's neatly reformatted...

The answer here was a good start. For my new project (an online, social-distance way of playing the excellent creative card game Joking Hazard) I ended up with a pair of alias like this:
alias joking_rsync='rsync -azP --exclude ".*/" --exclude ".*" --exclude "tmp/" /Users/LOCALUSER/data/dev/2020/jokinghazard USERNAME@SERVERNAME.com:/home/USERNAME/sites/temp.alienbill.com/'
alias joking_rsync_watch='joking_rsync; fswatch -o . | while read f; do joking_rsync; done'

It didn't work at first though because rsynch would ask for my password each time! (also I had to `brew install fswatch`)

The steps on this page worked really well to share an ssh key, and let rsynch work without bugging me. I guess I feel better about setting that up on my new mac that always requires at least a fingerprint to log in.

Earlier I had done something sort of similar and had better luck with 'filewatcher' but it has been a while for that - in this case rsync is doing more of the heavy lifting, so fswatch does the trick.

No comments:

Post a Comment