From ba99f752e8744974013e98724c16bdf079cfa85c Mon Sep 17 00:00:00 2001 From: lshprung Date: Mon, 11 Jan 2021 13:36:35 -0800 Subject: First commit --- markdown_preview.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 markdown_preview.sh (limited to 'markdown_preview.sh') diff --git a/markdown_preview.sh b/markdown_preview.sh new file mode 100755 index 0000000..dc6abbd --- /dev/null +++ b/markdown_preview.sh @@ -0,0 +1,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 -- cgit