Skip to content

Instantly share code, notes, and snippets.

@madx
Created October 8, 2014 16:07
Show Gist options
  • Save madx/600ab8c1b68ea860260a to your computer and use it in GitHub Desktop.
Save madx/600ab8c1b68ea860260a to your computer and use it in GitHub Desktop.
Quick and dirty markdown live previewer in bash using surf and xdotool
#!/bin/bash
render() {
marked source.md > output.html
}
cleanup() {
if [ -d /proc/$surf_pid/ ]; then
kill $surf_pid
fi
if [ -f .surf_xid ]; then
rm .surf_xid
fi
}
render
surf -x $(pwd)/output.html > .surf_xid &
surf_pid=$!
trap cleanup EXIT
inotifywait -qm source.md -e CLOSE_WRITE | while read; do
render
xdotool key --window `cat .surf_xid` ctrl+r
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment