Created
December 21, 2011 05:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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