#!/bin/bash
set -e
cd "$(dirname "$0")"
if ! [ -e one-section-per-line.txt ] || ! [ -e bookmark.txt ]; then
echo "Please run $(dirname "$0")/init first to initialise the book"
exit 1; fi
head -"$(cat bookmark.txt)" one-section-per-line.txt | tail -1 |
sed 's,
,\n\n,g;s,
,,g;s,*em>,*,g;s,,\n# ,g;s,,\n## ,g;s,,\n### ,g;s,,\n#### ,g;s,,,g'
echo
if [ "$(cat bookmark.txt)" -lt "$(wc -l < one-section-per-line.txt)" ]; then
echo "Run $(dirname "$0")/next to read on."
fi
if [ $(cat bookmark.txt) -gt 1 ]; then
echo "Run $(dirname "$0")/prev to go back."
echo "Run $(dirname "$0")/init to restart."
fi