-
Notifications
You must be signed in to change notification settings - Fork 0
/
inotify_loop
executable file
·67 lines (50 loc) · 1.02 KB
/
inotify_loop
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Runs a command when a file or files in directory are modified
path="$1"
shift
prog="$@"
if [ -d "$path" ]; then
IS_DIR=1
else
IS_DIR=0
fi
# If the command is not specified, try to guess it
if [ -z "$prog" ]; then
if [ "$IS_DIR" = 1 ]; then
if [ -f Makefile ]; then
prog="make"
fi
else
case $path in
*.tex)
prog="pdflatex -halt-on-error" ;;
esac
fi
fi
if [ -z "$prog" ]; then
echo "Don't know what command to run"
exit
fi
while :; do
read directory operation file < <(inotifywait --quiet --recursive -e create -e modify $path)
if [ "$IS_DIR" = 1 ]; then
if [[ "$file" =~ ^[0-9]{4}$ ]]; then
echo "Skipping '$file' (vim temp)"
else
echo "Waiting for '$file' to be available"
while [ ! -f $directory/$file ]; do
:
done
echo "Running '$prog'" >&2
# Eval is neeed to process shell file redirections
eval $prog
fi
else
# Wait for the file to be available
while [ ! -f $path ]; do
:
done
echo "Running $prog $path" >&2
eval $prog $path
fi
done