Skip to content

Instantly share code, notes, and snippets.

@laem
Last active August 29, 2015 14:16
Show Gist options
  • Save laem/fb342388383702c02d23 to your computer and use it in GitHub Desktop.
Save laem/fb342388383702c02d23 to your computer and use it in GitHub Desktop.
Watch for local changes, exluding according to ./.gitignore, to rsync to $dest
#!/bin/bash
#
# Fork of https://gist.github.com/senko/1154509#file-onchange-sh
if [ -z "$1" ]; then
echo "Specify an rsync dest as first argument"
exit -1;
fi
EVENTS="CREATE,CLOSE_WRITE,DELETE,MODIFY,MOVED_FROM,MOVED_TO"
inotifywait -e "$EVENTS" -m -r --format '%:e %f' . | (
WAITING="";
while true; do
LINE="";
read -t 1 LINE;
if test -z "$LINE"; then
if test ! -z "$WAITING"; then
echo "CHANGE";
WAITING="";
fi;
else
WAITING=1;
fi;
done) | (
while true; do
read TMP;
echo "yo"
rsync -avt --delete --filter=':- .gitignore' ./ $1
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment