Last active
August 22, 2016 08:36
-
-
Save stampycode/eb8b2a3fde337fc37c6bef3b20d58788 to your computer and use it in GitHub Desktop.
Mac fswatch file change propagation daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
code=0 | |
if [[ ! "$1" ]] || [[ "$1" && ! -d "$1" && "-h" != "$1" && "--help" != "$1" ]] || [[ "$2" && ! -d "$2" ]] ; then | |
code=1 | |
fi | |
if [[ ! "$2" || $code -gt 0 || "-h" = "$1" || "--help" = "$1" ]] ; then | |
echo Propagates file changes from one directory into another | |
echo usage: | |
echo " $0 <source_dir> <dest_dir>" | |
exit $code | |
fi | |
if [[ "$3" ]] ; then | |
TARG=`php -r "echo(substr('$3',1+strlen(realpath('$1'))));"` | |
DIR=`php -r "echo(dirname('$TARG'));"` | |
if [[ ! -f $1/$TARG ]] ; then | |
[[ ! -f "$2/$TARG" ]] && exit | |
echo -- $2/$TARG | |
rm -f "$2/$TARG" | |
exit | |
fi | |
if [[ ! -d $2/$DIR ]] ; then | |
echo +d $2/$DIR | |
mkdir -p "$2/$DIR" | |
fi | |
if [[ ! -f $2/$TARG ]] ; then | |
echo ++ $2/$TARG | |
else | |
echo ~~ $2/$TARG | |
fi | |
cp "$1/$TARG" "$2/$TARG" | |
exit | |
fi | |
echo propragating changes from $1 into $2... | |
fswatch $1 | xargs -n1 $0 $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment