Last active
August 29, 2015 14:10
-
-
Save fijiwebdesign/41de1aaf0f081f58d9be to your computer and use it in GitHub Desktop.
Watch and execute changed PHP files in a directory when they change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# inotifywait-execute-php.sh | |
# | |
# Example: | |
# inotifywait-execute-php.sh path/to/project/ | |
# | |
# Requires: https://github.com/thekid/inotify-win on windows | |
# | |
# author: Gabe LG <[email protected]> | |
# license: MIT | |
# | |
# correct usage instructions | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: | |
$0 path | |
Example: | |
$0 path/to/project/ | |
Note: | |
Exit with [Ctr+c] | |
" | |
exit 1 | |
fi | |
path=$1 | |
while (true); do | |
file=$( inotifywait $path | awk '{ print $3 }' ) | |
printf 'File changed: %s\n' "$file" | |
# execute if php file | |
is_php=$( echo $file | grep -P "\.php$" ) | |
if [ $is_php ]; then | |
printf 'Executing PHP file: %s\n' "$file" | |
php "$path/$file" | |
fi | |
sleep 1; # breathe | |
done; | |
# Notes: | |
# read from stdin | |
#input=`cat "-"` | |
#input=`less <&0` | |
#input=$( cat ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: