summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-01-11 13:36:35 -0800
committerlshprung <lshprung@yahoo.com>2021-01-11 13:36:35 -0800
commitba99f752e8744974013e98724c16bdf079cfa85c (patch)
tree35f42322fbf15a8feb3475e9b8e60dcd8f76ea5b
First commit
-rwxr-xr-xmarkdown_preview.sh31
1 files changed, 31 insertions, 0 deletions
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