-
Notifications
You must be signed in to change notification settings - Fork 3
/
watchmu
executable file
·46 lines (41 loc) · 1.28 KB
/
watchmu
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
#!/usr/bin/env bash
################################################################################
# watchmu - this script launches mupdf with whatever arguments are provided and
# then automatically reloads the PDF whenever it changes on disk. Eventually
# mupdf is supposed to support automatic reloads natively, but for the time
# being this hack works. This is nice for automatically updating PDF output
# from latex.
#
# (If you've never used mupdf before, it's a great lightweight PDF viewer.
# see http://www.mupdf.com/ for details)
#
# Dependencies:
# - inotifywait: https://github.com/rvoicilas/inotify-tools
# - xdotool: http://www.semicomplete.com/projects/xdotool/
#
# Usage:
# watchmu ./my_thesis.pdf
# watchmu -r92 ~/stuff/important_paper.pdf
#
# Version 2
# Matthew Malensek <[email protected]>
################################################################################
kill_mu() {
kill ${mupid}
exit $?
}
trap kill_mu SIGINT SIGTERM
wait_mu() {
inotifywait -qq -e close ${@}
while inotifywait -qq -t1 -e close ${@}; do :; done
}
mupdf ${@} &
mupid=${!}
filename="$(basename ${!#})"
while true; do
if ! ps -p ${mupid} &> /dev/null; then
break
fi
wait_mu ${!#}
xdotool search --pid ${mupid} --name "${filename}" key 'r' &> /dev/null
done