Skip to content

Commit 6e10870

Browse files
committed
Delete patched elements, when deleted from srcd
Handle create, modify, move, rename and delete events. Signed-off-by: David Pordomingo <[email protected]>
1 parent 749803b commit 6e10870

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

watcher

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,37 @@ function ctrl_c {
1010
}
1111

1212
function watch_inotify {
13-
inotifywait --recursive \
14-
--event modify,move,create,delete \
15-
$DIRECTORY_TO_OBSERVE
13+
inotifywait --recursive --monitor --quiet \
14+
--event modify,move,create,delete,attrib \
15+
${DIRECTORY_TO_OBSERVE} | awk -v SRCD="^srcd" -v SUPERSET="$(pwd)/superset" '{ \
16+
print $0; \
17+
if ($2 ~ "DELETE" || $2 ~ "MOVED_FROM") { \
18+
print "[deleted]: " $1$3; \
19+
print "rm -rf " gensub(SRCD, SUPERSET, 1, $1$3); \
20+
system("rm -rf " gensub(SRCD, SUPERSET, 1, $1$3)); \
21+
} else { \
22+
print "[modified]: " $1$3; \
23+
system("make --no-print-directory apply-patch"); \
24+
} \
25+
}';
1626
}
1727

1828
function watch_fswatch {
19-
fswatch --recursive --one-event \
20-
--event Created --event Updated --event Removed \
21-
${DIRECTORY_TO_OBSERVE}
29+
fswatch --recursive --event-flags \
30+
--event Created --event Updated --event Removed --event Renamed \
31+
--event MovedFrom --event MovedTo \
32+
--event OwnerModified --event AttributeModified \
33+
${DIRECTORY_TO_OBSERVE} | awk -v SRCD="$(pwd)/srcd" -v SUPERSET="$(pwd)/superset" '{ \
34+
print $0; \
35+
if ($2 ~ "Removed") { \
36+
print "[deleted]: " $1; \
37+
print "rm -rf " gensub(SRCD, SUPERSET, 1, $1); \
38+
system("rm -rf " gensub(SRCD, SUPERSET, 1, $1)); \
39+
} else { \
40+
print "[modified]: " $1; \
41+
system("make --no-print-directory apply-patch"); \
42+
} \
43+
}';
2244
}
2345

2446

@@ -43,6 +65,5 @@ fi
4365

4466
make --no-print-directory apply-patch
4567
echo -e "\033[1;92mWatching for changes in 'srcd'; using '${whichWatcher}' ...\033[0m"
46-
while watcher; do
47-
make --no-print-directory apply-patch
48-
done
68+
69+
watcher

0 commit comments

Comments
 (0)