forked from src-d/sourced-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher
executable file
·47 lines (40 loc) · 1.21 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
#!/bin/bash
trap ctrl_c SIGINT
function ctrl_c {
make --no-print-directory clean && \
echo -e "\e[92mPatch cleaned\e[0m" || \
echo -e "\e[33mCould not clean patch\e[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
wichWatcher=inotify
function watcher { watch_inotify; }
elif command -v fswatch > /dev/null 2>&1; then
wichWatcher=fswatch
function watcher { watch_fswatch; }
else
echo -e "\e[31m[ERROR] No watcher available\e[0m"
echo "Neither 'inotify' nor 'fswatch' are available."
echo "You can follow 'CONTRIBUTING.md' guidelines to install one of them,"
echo ""
echo -e "\e[33malternative:\e[0m"
echo " run 'make set-override' first,"
echo " and then 'make patch' every time you change a file in 'srcd' dir"
echo ""
exit 1
fi
make --no-print-directory apply-patch
echo -e "\e[92mWatching for changes in 'srcd'; using '${wichWatcher}' ...\e[0m"
while watcher; do
make --no-print-directory apply-patch
done