Skip to content

Instantly share code, notes, and snippets.

@derrickj
Created December 21, 2011 05:53
Show Gist options
  • Save derrickj/1504803 to your computer and use it in GitHub Desktop.
Save derrickj/1504803 to your computer and use it in GitHub Desktop.
This shell script creates a template file for a new jekyll post. Typing in the date, time and title in the exact format for the filename and inside the file is a tiny bit too tedious when it can easily be automated.
#!/bin/sh
# get title from stdin
/bin/echo -n "Title : "
read TITLE
SAFETITLE=$(/bin/echo -n $TITLE | tr -sc [:alpha:] - | tr [:upper:] [:lower:])
FILENAME=$(date -j +%Y-%m-%d)-${SAFETITLE}.md
echo file: $FILENAME
DIR="_posts"
while [ ! -d "$DIR" ]
do
/bin/echo -n "_posts directory: "
read DIR
done
if [ -e "${DIR}/${FILENAME}" ]
then
echo "File Exists: Doing nothing" >&2
exit 1
fi
DATESTR=$(date -j +"%Y-%m-%d %H:%M:%S")
/usr/bin/printf -- '---\nlayout: post\ntitle: %s\ndate: %s\n---\n\n' "$TITLE" "$DATESTR" >> "${DIR}/${FILENAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment