summaryrefslogtreecommitdiff
path: root/markdown_preview.sh
blob: 3327dda2c2a965886760954cdbdd2b8d6cacf04f (plain)
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
#!/bin/sh

#Variables
RUN=0
SLEEP=1

file -E $1 > /dev/null 2>&1

#Check for error in argument
if [ $? -gt 0 ]; then
	echo "Error: missing or incorrect argument. Must be a valid file"
	exit
fi

LAST_MOD=`stat $1 --printf=%Y`

#Initial run
pandoc -f markdown -t pdf -o /tmp/preview.pdf $1
zathura /tmp/preview.pdf &
PID=$(pidof -s zathura)

#Loop until zathura is closed
while [ $RUN -eq 0 ]; do
	if [ `stat $1 --printf=%Y` -gt $LAST_MOD ]; then
		LAST_MOD=`stat $1 --printf=%Y`
		pandoc -f markdown -t pdf -o /tmp/preview.pdf $1
	fi
	sleep $SLEEP
	RUN=$(ps --pid $PID; echo $?)
	RUN=$(echo $RUN | rev | cut -c 1)
done