Humanity

Edit the world by your favorite way

Markdown形式の文書をHTMLにして素早くFirefoxで見る

そんなスクリプトを書いた。
prereq_progに書いてあるプログラムがインストールされてないと動きません。


#!/bin/sh

prereq_prog="pandoc firefox perl"


if test $# = 0
then
    echo "specify markdown document." >&2
    exit -1

fi


for i in $prereq_prog
do
    if test ! -x `which $i`
    then
        echo "prereq program '$i' was not found..." >&2
        exit -1
    fi
done


tempname=`perl -e 'print join q(), localtime, q(.html)'`

if test ! -f $1
then
    echo "$1: No such a file" >&2
    exit -1
fi

pandoc $1 > /tmp/$tempname
firefox /tmp/$tempname
# NOTE: not found if firefox reloads.
rm /tmp/$tempname


移植性考えて[とか;とか使わないようにした。
でもそれ以外はあんま考えずに3分くらいで書いた。