Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A very minimalistic Bash clone of https://facebook.github.io/watchman/
#!/bin/bash
which inotifywait 2>/dev/null > /dev/null
if [[ $? != 0 ]]; then
echo "can't listen for events, install inotify-tools first"
exit 1
fi
directories=""
while [[ $# > 0 ]]; do
if [[ $1 == "--" ]]; then
shift
break
fi
directories="$directories $1"
shift
done
if [[ $directories == "" ]]; then
echo "no directories provided"
echo "usage: ./watchman.sh DIR1 DIR2 ... -- COMMAND ARG1 [injected: filename]"
exit 1
fi
tput reset
inotifywait --monitor --event close_write --recursive $directories |
while read path _ file; do
tput reset
filename="$path$file"
echo "$filename triggered executing '$@'"
echo ""
$@ $filename
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment