Last active
August 29, 2015 14:22
-
-
Save Qix-/46d9cc0b370c0f475004 to your computer and use it in GitHub Desktop.
WatchRun
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 | |
(cat > /usr/local/bin/watchrun) <<EOF | |
#!/bin/bash | |
# Watches the CWD recursively and runs a command | |
# whenever a file changes. | |
trap ctrl_c INT | |
function ctrl_c() { | |
echo "Terminating watchrun" | |
exit 3 | |
} | |
if [[ -z "\$1" ]]; then | |
echo "Missing command" 1>&2 | |
exit 2 | |
fi | |
if [[ -z "\$WATCH" ]]; then | |
export WATCH=`pwd` | |
fi | |
while true; do | |
sleep 0.1 || exit 1 | |
fswatch -r1x --exclude="\.git\/" -l 0.1 "\$WATCH" || exit 1 | |
\$* | |
done | |
EOF | |
chmod +x /usr/local/bin/watchrun | |
echo "Installed /usr/local/bin/watchrun" | |
echo "Make sure to install \`fswatch' (brew install fswatch)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment