BlogAlba/scripts/new-post

12 lines
613 B
Plaintext
Raw Permalink Normal View History

#!/bin/sh
2015-03-10 01:35:13 +00:00
read -ep 'Title of new post: ' TITLE
read -ep 'Tags for new post, comma-separated: ' TAGS
2015-03-10 00:55:45 +00:00
DATE=`date '+%Y-%m-%d %H:%M'`
2015-03-10 01:35:13 +00:00
FNAME="`date '+%Y%m%d'`.`echo "$TITLE"|tr '[:upper:]' '[:lower:]'|tr -cd '[:alnum:]'`.md"
cp posts/post.template posts/$FNAME
2015-03-10 01:35:13 +00:00
env V="$TITLE" perl -pi -e 's/^(title: )/$1$ENV{V}/' posts/$FNAME
env V="$DATE" perl -pi -e 's/^(date: )/$1$ENV{V}/' posts/$FNAME
env V="$TAGS" perl -pi -e 's/^(tags: )/$1$ENV{V}/' posts/$FNAME
2015-03-10 00:55:45 +00:00
[ -z "$EDITOR" ] && echo "EDITOR environment variable not set. Please set this to your preferred editor, or open $FNAME manually" && exit
$EDITOR posts/$FNAME