Skip to content

Instantly share code, notes, and snippets.

@mwcz
Last active May 28, 2016 06:42
Show Gist options
  • Save mwcz/2986905 to your computer and use it in GitHub Desktop.
Save mwcz/2986905 to your computer and use it in GitHub Desktop.
watchrun script for running a command when any file in the current dir tree changes
#!/bin/sh
# USAGE: ./watchrun.sh COMMAND
# New credit to: http://exyr.org/2011/inotify-run/
# this script will wait for changes in the current directory tree, and when one occurs, it will run COMMAND, then resume waiting
# requires inotify-tools:
# sudo apt-get install inotify-tools
# or:
# yum install inotify-tools
FORMAT=$(echo -e "\033[1;33m%w%f\033[0m written")
while inotifywait -e close_write -qr --format "$FORMAT" .
do
"$@"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment