bin/witness
#!/bin/sh
#
# witness - watch a file for changes & run a command
file="$1"
shift
command="$@"
get_access_time() {
stat -c %Z "$1"
}
ltime="$(get_access_time "$file")"
while true; do
atime="$(get_access_time "$file")"
if [ "$atime" != "$ltime" ]; then
printf "witness: '%s' changed, running '%s'\n" "$file" "$command"
$command
ltime="$atime"
fi
sleep 0.5
done