gitea/watch

21 lines
606 B
Plaintext
Raw Normal View History

#!/bin/bash
DEBOUNCE=1.0
DIR=$(dirname "$(readlink -f "$0")") || exit
export WATCH_DIR="$DIR/frontend/"
export WATCH_VERBOSE=1
COMMAND="$DIR/restart $1 $2"
# LOGFILE="$DIR/watch.log"
echo "watching $WATCH_DIR with $COMMAND"
inotifywait -mqr -e MODIFY $WATCH_DIR |
while read ; do
# debounce extra events
currentTime=$(date +'%H%M%S.%N')
delta=$(bc <<< "$lastRunTime - $currentTime")
# echo "$currentTime, $lastRunTime, $delta"
if (( $(echo "$delta < -$DEBOUNCE" | bc -l) )); then
echo $COMMAND
$COMMAND
lastRunTime=$(date +'%H%M%S.%N')
fi
done