Skip to content

Instantly share code, notes, and snippets.

@icchy
Last active January 30, 2018 10:37
Show Gist options
  • Save icchy/6293952df18ae4db6af3a59906d336d4 to your computer and use it in GitHub Desktop.
Save icchy/6293952df18ae4db6af3a59906d336d4 to your computer and use it in GitHub Desktop.
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