add witness for watching
Jes Olson j3s@c3f.net
Tue, 28 Feb 2023 11:18:07 -0800
1 files changed,
23 insertions(+),
0 deletions(-)
jump to
A
bin/witness
@@ -0,0 +1,23 @@
+#!/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