Created
June 24, 2013 03:29
-
-
Save 0cjs/5847587 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
# | |
# mdpreview - preview a markdown file | |
# | |
# Idea from: | |
# https://ubuntuincident.wordpress.com/2011/05/05/readme-markdown-on-github/ | |
# | |
# This does not handle the Github variations documented at: | |
# https://help.github.com/articles/github-flavored-markdown | |
# You may want to try using a gist to get a more accurate preview. | |
# https://gist.github.com/ | |
# | |
# To-do: add an option to keep running in the background, monitoring the | |
# input file, and, when it changes, regenerate the HTML file and have | |
# the browser reload it. | |
# | |
set -e | |
err() { echo 1>&2 "ERROR: $@"; exit 1; } | |
markdown --version >/dev/null 2>&1 \ | |
|| err "Cannot execute 'markdown' program (install 'markdown' package?)" | |
tmpfile=$(mktemp --tmpdir $(basename $0).XXXXX.html) | |
trap "rm -f $tmpfile" EXIT | |
markdown > $tmpfile "$@" | |
# Should be be using xdg-open instead? | |
# Does sensible-browser background automatically when no browser is running? | |
sensible-browser $tmpfile | |
sleep 1 # Give browser a chance to load page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment