-
Notifications
You must be signed in to change notification settings - Fork 3
/
while_inotifywait
executable file
·22 lines (20 loc) · 1.09 KB
/
while_inotifywait
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# it's possible to watch on all these events but then new files created, e.g.
# swap file will trigger calls as well as on temporary changes to files when
# they are actually not ready to be executed so better just use "close_write"
# to reduce the calls
#while inotifywait -q -r -e close_write,moved_to,create . ; do "$@" ; done
# with 'close_write,moved_to' one can still have the problem that a
# file is not completely written or only a temporary file is written before
# the target file is done being written and the command triggered fails to find the
# file at all.
# https://stackoverflow.com/questions/46542819/bash-script-inotifywait-wait-for-file-completely-written-before-proceding mentions as well that 'close_write'
# should be enough. Following
# https://stackoverflow.com/questions/10300835/too-many-inotify-events-while-editing-in-vim
# the missing part seems to have been that vim writes a temporary file first
# before writing the real file which I disabled and this seems to have done
# the trick
run() {
"$@"
}
run "$@"
while inotifywait -q -r -e close_write,moved_to . ; do run "$@" ; done