Skip to content

Instantly share code, notes, and snippets.

@michaelneu
Created March 13, 2020 21:25
Show Gist options
  • Save michaelneu/91508c27d7c7b70e4cc6d93783b188a4 to your computer and use it in GitHub Desktop.
Save michaelneu/91508c27d7c7b70e4cc6d93783b188a4 to your computer and use it in GitHub Desktop.
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