Skip to content

Instantly share code, notes, and snippets.

@icchy
Last active Jan 30, 2018
Embed
What would you like to do?
rsync with fswatch
#!/bin/sh
remote_dir=host:path/to/remote/dir
local_dir=path/to/local/dir
usage () {
echo "usage: $0 [pull|push|sync]" >&2
}
check () {
which fswatch >/dev/null || (echo "fswatch not found"; exit 1)
which rsync >/dev/null || (echo "rsync not found"; exit 1)
}
pull () {
rsync -avz -u -e ssh $remote_dir `dirname $local_dir`
}
push () {
rsync -avz -u --delete --exclude ".git/" -e ssh $local_dir `dirname $remote_dir`
}
check
case $1 in
pull)
pull
;;
push)
push
;;
sync)
# pull
fswatch -e "\.git/" -o $local_dir | while read $line; do
push
done
;;
*)
usage
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment