-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatch.sh
executable file
·44 lines (32 loc) · 1019 Bytes
/
watch.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
build_project () {
opam exec -- dune build @all
if [[ ! "$?" -eq 0 ]]; then
echo "failed to build project"
exit 1
fi
}
run_project () {
opam exec -- dune exec -- ./bin/main.exe -D &
}
build_project
run_project
BG_PID="$!"
echo "$BG_PID"
inotifywait -m . -r -e "MODIFY" --exclude "(_build/*|.git/*|.*/\.#.*|\./.*\.db|\./.*\.db-wal|\./.*\.db-shm)" |
while read -r directory events filename; do
echo "received event $events on $directory:$filename, restarting"
if opam exec -- dune build @all; then
while (ps -p "$BG_PID" > /dev/null) && [[ ! -z "$BG_PID" ]]; do
echo kill -INT $BG_PID
kill -INT $BG_PID
done
while lsof -i TCP | grep -q 7331; do
BAD_PID=$(lsof -i TCP | grep -v 7331 | cut -d ' ' -f 3)
echo "Killing $BAD_PID"
kill -9 "$BAD_PID"
done
run_project
BG_PID="$!"
fi
done