force adding a whenfilechanges function for all

This commit is contained in:
ville rantanen
2013-04-12 14:07:26 +03:00
parent e697b78e94
commit e9a70623a5

View File

@@ -77,3 +77,30 @@ function qcd() {
fi fi
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
}