diff --git a/qcd_function b/qcd_function index bc73c84..e6a256c 100644 --- a/qcd_function +++ b/qcd_function @@ -77,3 +77,30 @@ function qcd() { fi fi } + + +function whenfilechanges() { + [ -z "$1" ] && { echo 'Usage: whenfilechanges "file" "some" "command" + Follows the modification time of the "file" and runs the command + at every change. ' + return + } + [ -e "$1" ] || { echo $1 not found + return + } + + fname=$1 + shift 1 + otime=$( stat -c %Z "$fname" ) + while : + do ntime=$( stat -c %Z "$fname" ) + [ "$ntime" -ne "$otime" ] && { + eval "$@" + otime="$ntime" + } + + sleep 2 + done + +} +