Skip to content

Instantly share code, notes, and snippets.

@Qix-
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qix-/46d9cc0b370c0f475004 to your computer and use it in GitHub Desktop.
Save Qix-/46d9cc0b370c0f475004 to your computer and use it in GitHub Desktop.
WatchRun
#!/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