Last active
October 25, 2018 20:25
-
-
Save ngyuki/7786721 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
# example) | |
# ./phpunit-watch src/ tests/ -c tests/ --colors | |
set -e | |
set -u | |
function usage | |
{ | |
{ | |
echo "Usage: $0 <path>... [--] [options]..." | |
cat <<__END__ | |
path Monitor paths. | |
options PHPUnit command line options. | |
e.g.) | |
1. Monitoring src/ tests/ and execute "phpunit -c tests/ --colors" | |
$0 src/ tests/ -c tests/ --colors | |
2. Monitoring src/ tests/ and execute "phpunit tests/" | |
$0 src/ tests/ -- tests/ | |
__END__ | |
} 1>&2 | |
exit 1 | |
} | |
paths=() | |
while [ $# -ne 0 ]; do | |
if [ "${1#-}" == "$1" ]; then | |
paths+=( "$1" ) | |
else | |
break | |
fi | |
shift | |
done | |
if [ "${#paths[@]}" -eq 0 ]; then | |
usage | |
fi | |
if [ $# -ne 0 ]; then | |
if [ "$1" == "--" ]; then | |
shift | |
fi | |
fi | |
echo "Monitor paths: ${paths[@]}" | |
echo "PHPUnit options: $@" | |
inotifywait -e create,delete,modify,move --exclude '.*\.sw[pox]' -m -r "${paths[@]}" | | |
while read; do | |
while read -t 0.3; do | |
: | |
done | |
phpunit "$@" &&: | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment