-
Notifications
You must be signed in to change notification settings - Fork 15
/
mdpreview
executable file
·46 lines (36 loc) · 1.16 KB
/
mdpreview
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
# Set help text to be displayed later as needed
HELP="Usage: mdpreview [MARKDOWN FILE]"
# Locate the "multimarkdown" binary
MMDCMD=$(command -v multimarkdown)
# Check for presence of the "multimarkdown" command
if [ ! -x $MMDCMD ]; then
echo "MultiMarkdown does not appear to be installed"
exit 1
fi
# Ensure that only a single parameter was passed
# Display help text if more than 1 parameter was supplied
if [ "$#" -ne 1 ]; then
echo "Error: Incorrect number of parameters. Please supply only a single file name."
echo
echo $HELP
exit 1
fi
# Check to see if the user supplied "--help"
if [ "$1" = "--help" ]; then
echo $HELP
exit 0
fi
# Generate a temp file
TMPFILE="$(date +%Y-%m-%d-%H-%M)-md-preview.html"
# If a file with the same name exists, remove it
if [ -f /tmp/$TMPFILE ]; then
rm -f /tmp/$TMPFILE
fi
# Generate new Markdown preview file
$MMDCMD --output=/tmp/$TMPFILE --to=html --full "$1"
# Open generated preview file in Firefox
# Assumes firefox binary is in the path
nohup /opt/firefox/firefox --new-window file:///tmp/$TMPFILE &> /dev/null &
# Remove preview file after 5 seconds
sleep 5; rm /tmp/$TMPFILE