Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active October 25, 2015 15:06
Show Gist options
  • Save bordoni/e929cc086eee476aae31 to your computer and use it in GitHub Desktop.
Save bordoni/e929cc086eee476aae31 to your computer and use it in GitHub Desktop.
# !sh
# Requires fswatch -- https://github.com/emcrisostomo/fswatch
# Usage
# wsync ~/wp-content/plugins ~/dev/tribe/*
# wsync $destination $from
function wsync {
# First Param as the the place where the files will go
to=$1
# All other Params are the folders to watch
from=(`echo $(echo $@ | xargs -n1) | sed "s,${to} *,,g"`)
# Exclude string
rsync_exclude="--exclude=.git --exclude=node_modules --exclude=.sass-cache --exclude=.DS_Store --exclude=.svn"
# Create the Arguments for `rsync`
rsync_args="--archive --itemize-changes --checksum --times --perms --human-readable --delete ${from} ${to} ${rsync_exclude}"
echo "\n ┏\"$to\""
# Output a nice log
for line_from in $from; do
echo " ┣━❱ \"$line_from\""
done
echo " ┗┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ \n"
# Rsync when starting
echo "┏┫`date +%H-%M-%S`┣┓" && echo "┡┉┉┉┉┉┉┉┉┉┉┩" && (`echo "rsync ${rsync_args}"`) && echo "┕┉┉┉┉┉┉┉┉┉┉┙\n"
# Now watch for changes
fswatch --one-per-batch --exclude=\.git $from | (while read; do echo "┏┫`date +%H-%M-%S`┣┓" && echo "┡┉┉┉┉┉┉┉┉┉┉┩" && (`echo "rsync ${rsync_args}"`) && echo "┕┉┉┉┉┉┉┉┉┉┉┙\n"; done)
}
@bordoni
Copy link
Author

bordoni commented Oct 25, 2015

How to Install

curl -o wsync.sh https://gist.githubusercontent.com/bordoni/e929cc086eee476aae31/raw/e34f54f8ad72ee663bb493b68cd2bfe06d5338a4/wsync.sh && mv -f ./wsync.sh ~/.wsync.sh && chmod +x ~/.wsync.sh
echo "source ~/.wsync.sh" >> ~/.zshrc

If you are not using ZSH, you should change ~/.zshrc to ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment