#!/bin/sh

# _posts/2017-07-13-csh-sensible-defaults.md

ts=`date +%Y-%m-%d`

while :; do
    echo -n "Enter blog post title: "
    read title
    echo -n "Title <$title> ok [Yn]? "
    read yesno
    case $yesno in
        N|n|no|No|NO)
            :
            ;;
        *)
            break
            ;;
    esac
done

while :; do
    echo -n "Enter category: "
    read category
    echo -n "Category <$category> ok [Yn]? "
    read yeasno
    case $yesno in
        N|n|no|No|NO)
            :
            ;;
        *)
            break
            ;;
    esac
done

slug=`echo "$title" | tr '[A-Z]' '[a-z]' | sed -e 's/ /-/g'`
post="_posts/${ts}-$slug.md"

cat << EOF > $post
---
layout: post
title: "$title"
tags:
- $category
---


EOF

editor=vi

if type emacs > /dev/null 2>&1; then
  editor=emacs
fi
$editor $post

echo "Wrote $post"
echo "Consider running 'make force' inside jail"
