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,
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.