Last active
August 13, 2016 17:13
-
-
Save kevsmith/cde0a679b25ca3fc65ae to your computer and use it in GitHub Desktop.
Markdown previewer using pandoc, chrome-cli, and fswatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# To install dependencies: brew install pandoc chrome-cli fswatch | |
# To use: mdpreview /path/to/content.md | |
monitored_file=`basename $1` | |
preview="/tmp/${monitored_file}.html" | |
preview_url="file://${preview}" | |
trap "rm -f ${preview};exit;" SIGINT SIGTERM | |
# Remove any old preview versions | |
rm -f ${preview} | |
# Generate preview | |
pandoc -f markdown_github -t html5 $1> ${preview} | |
# Open in Chrome | |
tab_id=`chrome-cli open ${preview_url} | grep Id | cut -d: -f2` | |
# Now we loop until killed regenerating and reloading | |
# the preview whenever the source document changes | |
while [ 1 ] | |
do | |
fswatch -L -0 -1 $1 > /dev/null | |
chrome-cli reload -t${tab_id} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment