#!/usr/bin/env sh
#
# deps: asciidoctor

set -o errexit
set -o nounset

if [ "$1" = "" ]; then
echo "Usage: ${0##*/} <file.adoc>"; exit 2
fi

input=$1

if [ "$1" = "-" ]; then
input=/tmp/tmp.adoc
command -p -- rm -r -f -- "${input}"
while IFS=$(printf ' \n\t') read -r line; do
  echo "${line}" >>"${input}"
done
fi

file=/tmp/tmp.html

asciidoctor "${input}" -a source-highlighter=coderay -o "${file}" >/dev/null 2>&1
chromium "${file}" >/dev/null 2>&1 &
