Fork me on GitHub

Welcome

Come across a Markdown document while on the command line? That's too bad, because it'd look better rendered in a browser. Here, put this in your .bashrc:

md() {
    declare -r sys_name=$(uname -s)
    if [[ $sys_name == Darwin* ]]; then
        declare -r T=$(mktemp $TMPDIR$(uuidgen).html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        open $T
    elif [[ $sys_name == CYGWIN* ]]; then
        declare -r T=$(mktemp --suffix=.html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        cygstart $T
    else
        declare -r T=$(mktemp --suffix=.html)
        curl -s -X POST --data-binary @"$1" https://md.dlma.com/ > $T
        if [[ -z "${WSL_DISTRO_NAME}" ]]; then
            gio open $T
            echo "rm \"$T\" >/dev/null 2>&1" | at now + 2 minutes
        else
            # Set BROWSER to your web browser's path
            "$BROWSER" $(realpath --relative-to=$PWD $T)
        fi
    fi
}

And then you have an md command to view the document in a browser, which you can use like:

md README.md