my dotz
1#!/bin/sh
2#
3# witness - watch a file for changes & run a command
4
5file="$1"
6shift
7command="$@"
8
9get_access_time() {
10 stat -c %Z "$1"
11}
12
13ltime="$(get_access_time "$file")"
14
15while true; do
16 atime="$(get_access_time "$file")"
17 if [ "$atime" != "$ltime" ]; then
18 printf "$ %s\n" "$command"
19 $command
20 ltime="$atime"
21 fi
22 sleep 0.5
23done