Skip to content

Instantly share code, notes, and snippets.

@fijiwebdesign
Last active May 28, 2016 04:36
Show Gist options
  • Save fijiwebdesign/573f4028931c89c3eada to your computer and use it in GitHub Desktop.
Save fijiwebdesign/573f4028931c89c3eada to your computer and use it in GitHub Desktop.
Inotifywait watch files and run command
#!/bin/bash
# inotifywait-cmd.sh
#
# Example:
# inotifywait-cmd.sh test/ 'phpunit --verbose test/ModelReferencesTest.php'
#
# Requires: https://github.com/thekid/inotify-win on windows
#
# author: Gabe LG <gabe@fijiwebdesign.com>
# license: MIT
#
# correct usage instructions
if [ "$#" -ne 2 ]; then
echo "Usage:
$0 path 'command'
Example:
$0 test/ 'phpunit --verbose test/ModelReferencesTest.php'
Note:
Exit with [Ctr+c]
"
exit 1
fi
# start inotifywait and eval command when files change
while true; do
inotifywait -r $1 && eval $2
sleep 1 # allow ctr+c
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment