small pixel drawing of a pufferfish dotfiles

add witness for watching
Jes Olson j3s@c3f.net
Tue, 28 Feb 2023 11:18:07 -0800
commit

c55c7e8ad4225f94aa4c155848231d03a661785c

parent

5f09e7daf0b61e015eae5e0f402d75bbdf76adf9

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