Last active
September 25, 2017 20:45
-
-
Save zachwalton/395c0916081aac1f00d2f3b0f8cf306d to your computer and use it in GitHub Desktop.
rsync files when an fswatch event is detected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function tracked_by_git() { | |
cd $(dirname $1) | |
git ls-files --error-unmatch $1 &>/dev/null | |
ret=$? | |
cd - &>/dev/null | |
return $ret | |
} | |
function remote_sync() { | |
echo "Syncing $1 to $2..." | |
local_dir=$1 | |
IFS=: read remote_host remote_dir <<< "$2" | |
fswatch $local_dir | while read event; do | |
if ! tracked_by_git "$event"; then | |
echo 1>&2 "[debug] ignoring file not tracked by git: ${event}..." | |
else | |
remote_path="$remote_dir${event#$local_dir}" | |
echo "[info] syncing $event to $remote_host:$remote_path..." | |
rsync &>/dev/null $event $remote_host:$remote_path | |
echo "[info] synced $event to $remote_host:$remote_path..." | |
fi | |
done | |
} |
Author
zachwalton
commented
Sep 25, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment