Skip to content

Instantly share code, notes, and snippets.

@bordoni
Created April 9, 2016 03:42
Show Gist options
  • Select an option

  • Save bordoni/58227c92cf29ce09c8a345b63e86b7a5 to your computer and use it in GitHub Desktop.

Select an option

Save bordoni/58227c92cf29ce09c8a345b63e86b7a5 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment