-
-
Save bitzip/fcb7a9c5872439329349fe455ee05406 to your computer and use it in GitHub Desktop.
watch is a linux bash script to monitor file modification recursively and execute bash commands as changes occur
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 | |
# script: watch | |
# author: Mike Smullin <[email protected]> | |
# license: GPLv3 | |
# description: | |
# watches the given path for changes | |
# and executes a given command when changes occur | |
# usage: | |
# watch <path> <cmd...> | |
# | |
path=$1 | |
shift | |
cmd=$* | |
sha=0 | |
update_sha() { | |
sha=`find $path -name '*.py' -printf '%Tc %p\n' | sha1sum` | |
} | |
update_sha | |
previous_sha=$sha | |
build() { | |
echo -en " building...\n\n" | |
$cmd | |
echo -en "\n--> resumed watching." | |
} | |
compare() { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then | |
echo -n "change detected," | |
build | |
previous_sha=$sha | |
fi | |
} | |
trap exit SIGINT | |
echo -e "--> Press Ctrl+C to force build, Ctrl+\\ to exit." | |
echo -e "--> watching..." | |
while true; do | |
compare | |
sleep 15 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment