summaryrefslogtreecommitdiff
path: root/markdown_preview.sh
blob: dc6abbd37fdf508c4692d93bc6ddaf1c7f52e080 (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

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`
echo $LAST_MOD

#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 5
	RUN=$(ps --pid $PID; echo $?)
	RUN=$(echo $RUN | rev | cut -c 1)
done