Created
September 25, 2010 14:30
-
-
Save timwienk/596888 to your computer and use it in GitHub Desktop.
Watches packages' directories for changes and executes a command when detecting a change.
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
#!/bin/sh | |
# | |
# Requires inotify-tools to be installed. | |
usage(){ | |
echo "Watches packages' directories for changes and executes" | |
echo 'a command when detecting a change.' | |
echo | |
echo 'This script requires inotify-tools to be installed.' | |
echo | |
echo "Usage: $0 <command> <packages...>" | |
echo | |
echo 'arguments:' | |
echo ' <command> The command to execute when detecting a change.' | |
echo ' <packages> Packages (registered to ~/.package.yml) to' | |
echo ' watch.' | |
echo | |
echo 'example:' | |
echo " $0 'packager build More/* > more.js' Core More" | |
} | |
if [ "$1" == '-h' -o "$1" == '--help' -o -z "$1" ]; then | |
usage | |
exit | |
fi | |
getpackagedirs(){ | |
for PACKAGE in "$@"; do | |
PKG=`sed -n "/^$PACKAGE:/ { s/^$PACKAGE://; />$/n; s/^ \+//; p }" ~/.packages.yml` | |
if [ -f "$PKG" ]; then | |
PKG=`dirname "$PKG"` | |
fi | |
if [ -d "$PKG" ]; then | |
echo "$PKG" | |
fi | |
done | |
} | |
COMMAND=$1 | |
shift | |
DIRS=`getpackagedirs "$@"` | |
echo -e "Watching directories:\n$DIRS\nPress ctrl-c to stop." >&2 | |
while true; do | |
inotifywait -r --exclude '.*(\.sw\w+|~)$' -e close_write -e move -e create -e delete $DIRS >&2 2> /dev/null | |
sh -c "$COMMAND" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment