Wrote a short script this morning to automate the process of creating new posts. It asks for a title, and the script does the rest: it strips non-ASCII characters from the filename, dates it, adds YML front matter, and sticks it in the drafts directory.

I definitely spent more time writing the script than I would save every 15 seconds it takes to create a new file, name it after today’s date, and copy the front matter. Still, it feels efficient.

Here’s a video of it in action:

And here’s the code:

read -p "Post title: " title;
#replace spaces with underscores, remove all non-alphanumeric characters, convert to lowercase, and truncate the filename to 64 characters long
cleantitle=$(echo $title | sed "s/ /_/g" | sed "s/[^a-zA-Z0-9_]//g" | tr "[:upper:]" "[:lower:]" | cut -c 1-64);
#add date to filename
date=`date +%Y-%m-%d`;
#create file
touch "/home/pierre/Documents/blog/site_content/_drafts/$filename";
echo "---
layout: post
title: $title
tags: []
comment: true
---" > "/path_to_blog/$filename";
#ideas for improvement: maybe could add an input for tags

Plus, for future reference, here’s the command I used to capture my desktop in ffmpeg:

ffmpeg -f x11grab -i :0.0 -video_size cif -r 30 -an -c:v libvpx post_creation_script_capture.webm