Helper script for creating posts with WWW::StaticBlog

There’s always another yak that needs shaving. Since creating posts with WWW::StaticBlog wasn’t fast enough for my tastes, I made a small script to make it even faster!

Before, I would create the directory hirarchy, if I haven’t yet made a post this month, coming up with a file name that has some relavence to the post contents, but is still sane for a file name, and opening it up in the editor, creating the Title:, and Author: “headers”, and finally getting down to writing the silly post.


post_date="$(date +%Y/%m)"


if [ "$title" == "" ];
    read -e -p 'Post title: ' title

filename="$(echo -n "$title" | tr -c '[:alnum:]' '_')"

mkdir -p articles/$post_date


echo "Title: $title"                    > $new_post
echo "Author: $(git config" >> $new_post
echo                                   >> $new_post
echo                                   >> $new_post

git add $new_post

vim -c 'set tw=72' '+/^$/+' -c 'nohl' $new_post

By saving this as ~/bin/git-new-post, I automatically get a new Git command. Now, I can just type git new-post from my site’s repository, and I’ll be prompted for the post’s title (with readline support), and the directories will be created for me, the title will be sanitized into a reasonable file name, the empty post with just the headers will be added to Git, and the file will be opened up in vim, with the cursor at the end, ready for me to just start writing.

Optionally, I can provide the title to new-post with git new-post Some title, and it won’t bother prompting me.