-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinotifydo
executable file
·29 lines (25 loc) · 1.18 KB
/
inotifydo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# credit: chrstphr
# initialize the last time we synced (seconds since 1970-01-01)
last_synced_time=0
inotifywait --exclude '.git' -mrq -e modify -e create -e delete --timefmt '%s' --format '%T %e:%w%f' $2 | while read timestamp event; do
echo Event: "$event"
echo Timestamp: "$timestamp"
# Give the file system time to properly handle the file changes that occurred
sleep 0.2
# if the timestamp is more than 10 seconds ago, we're not syncing it. We don't sync because this means that the server is extremely slow to respond and we need to clear the event queue.
current_time="$(date +%s)"
if [ $(("$current_time" - "$timestamp")) -gt 10 ]; then
echo "Ignoring event because it happened far in the past"
continue
fi
# only if the last update is more than 1 second ago do we want to handle this event
if [ $(("$timestamp" - "$last_synced_time")) -gt 1 ]; then
last_synced_time="$timestamp"
echo Calling git_upd
"$@" 2>&1 | awk '{print " ",$0}'
echo Finished syncing at "$(date)"
else
echo Event skipped because it occurred less than the wait time after the previous handled event
fi;
done;