Currently inotifywait
is watching git server folders. End it emits only when specific file modified. The problem is, when changes are pushed to git server,
As I mentioned in your other question, you can setup first a post-receive hook which would checkout the repo for you whenever there is a push done to the Git server.
Not only can you test your inotify
function when monitoring those files changed on checkout, but you could even consider not using inotify
at all, and using the hook to trigger your notification.
A post-receive hook can list files, and you can then trigger your notification only for certain files.
Here is how I solved it for my own needs. I am monitoring a path so that it will auto-compile for syntax errors. And I was bothered with the duplicate events emitted by inotifywait
. Add the syncheck
function into your .bashrc
:
syncheck() {
declare -A fileMap
inotifywait --exclude .swp --format '%w%f' -e modify,create -m -r -q $* | \
while read FILE; do
es=$(date +'%s')
case "$FILE" in
*.hs)
if [[ ${fileMap[$FILE]} != $es ]];then
sdiff=$((es-${fileMap[$FILE]:-0}))
fileMap[$FILE]=$es
((sdiff < 3)) && continue
ghc -fno-code $FILE
echo "---------------------------------------------"
fi
;;
esac
done
}
How to use:
cd ~/src/proj/
. ~/.bashrc
syncheck .
In another terminal, modify or create a Haskell
file in ~/src/proj/
location. The syncheck
while-loop will detect this and auto-compile for syntax errors.
The key idea to this duplicate events suppression solution is Unix`s epoch seconds and bash dictionary.