-
Notifications
You must be signed in to change notification settings - Fork 15
/
watcher
executable file
·48 lines (41 loc) · 1.31 KB
/
watcher
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
45
46
47
48
#!/bin/bash
trap ctrl_c SIGINT
function ctrl_c {
make --no-print-directory clean && \
echo -e "\033[1;92mPatch cleaned\033[0m" || \
echo -e "\033[1;33mCould not clean patch\033[0m"
exit $?
}
function watch_inotify {
inotifywait --recursive \
--event modify,move,create,delete \
$DIRECTORY_TO_OBSERVE
}
function watch_fswatch {
fswatch --recursive --one-event \
--event Created --event Updated --event Removed \
${DIRECTORY_TO_OBSERVE}
}
if command -v inotifywait > /dev/null 2>&1; then
whichWatcher=inotify
function watcher { watch_inotify; }
elif command -v fswatch > /dev/null 2>&1; then
whichWatcher=fswatch
function watcher { watch_fswatch; }
else
echo -e "\033[1;31m[ERROR] No watcher available\033[0m"
echo "Neither 'inotify' nor 'fswatch' are available."
echo "You can follow 'CONTRIBUTING.md' guidelines to install one of them,"
echo ""
echo -e "\033[1;33m[alternative]\033[0m follow these steps:"
echo "1. run 'make set-override' first,"
echo "2. then 'make patch' every time you change a file in 'srcd' dir"
echo "3. and 'make clean' once you finish developing"
echo ""
exit 1
fi
make --no-print-directory apply-patch
echo -e "\033[1;92mWatching for changes in 'srcd'; using '${whichWatcher}' ...\033[0m"
while watcher; do
make --no-print-directory apply-patch
done