Skip to content

Commit 0809806

Browse files
committed
Handle move (and rename) events
Signed-off-by: David Pordomingo <[email protected]>
1 parent 078a869 commit 0809806

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

watcher

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@ function ctrl_c {
1212
function watch_inotify {
1313
inotifywait --recursive --monitor --quiet \
1414
--event modify,move,create,delete,attrib \
15-
${DIRECTORY_TO_OBSERVE} | awk '{ \
16-
if ($2 ~ "DELETE") { \
17-
print "deleted: " $1$3; \
18-
system("rm -rf " gensub(/^srcd/, "superset", 1, $1$3)); \
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)); \
1921
} else { \
20-
print "modified: " $1$3; \
22+
print "[modified]: " $1$3; \
2123
system("make --no-print-directory apply-patch"); \
2224
} \
2325
}';
2426
}
2527

2628
function watch_fswatch {
27-
fswatch --recursive --event-flags
29+
fswatch --recursive --event-flags \
2830
--event Created --event Updated --event Removed --event Renamed \
2931
--event MovedFrom --event MovedTo \
3032
--event OwnerModified --event AttributeModified \
31-
${DIRECTORY_TO_OBSERVE} | awk '{ \
33+
${DIRECTORY_TO_OBSERVE} | awk -v SRCD="$(pwd)/srcd" -v SUPERSET="$(pwd)/superset" '{ \
34+
print $0; \
3235
if ($2 ~ "Removed") { \
33-
print "deleted: " $1; \
34-
system("rm -rf " gensub(/^srcd/, "superset", 1, $1)); \
36+
print "[deleted]: " $1; \
37+
print "rm -rf " gensub(SRCD, SUPERSET, 1, $1); \
38+
system("rm -rf " gensub(SRCD, SUPERSET, 1, $1)); \
3539
} else { \
36-
print "modified: " $1; \
40+
print "[modified]: " $1; \
3741
system("make --no-print-directory apply-patch"); \
3842
} \
3943
}';

0 commit comments

Comments
 (0)