12 lines
613 B
Bash
Executable File
12 lines
613 B
Bash
Executable File
#!/bin/sh
|
|
read -ep 'Title of new post: ' TITLE
|
|
read -ep 'Tags for new post, comma-separated: ' TAGS
|
|
DATE=`date '+%Y-%m-%d %H:%M'`
|
|
FNAME="`date '+%Y%m%d'`.`echo "$TITLE"|tr '[:upper:]' '[:lower:]'|tr -cd '[:alnum:]'`.md"
|
|
cp posts/post.template posts/$FNAME
|
|
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
|
|
[ -z "$EDITOR" ] && echo "EDITOR environment variable not set. Please set this to your preferred editor, or open $FNAME manually" && exit
|
|
$EDITOR posts/$FNAME
|