I haven't played around with bash so much before, but I'm learning by trying to automate things I do repeatedly. I found myself often starting a new Jekyll post with that magical filename format: YYYY-MM-DD-title.md
. So I decided to try and get that done using an alias, which didn't really work, so I ended up adding a function to my .bashrc:
function editpost()
{
vim $(date +"%Y-%m-%d-$1.md")
}
So now I can quickly start a Jekyll post with that title by going into my posts folder and using the command
editpost title-of-new-post
and it will open a file in with the formatted date, the title, and the .md suffix. Fairly handy.
I had originally intended it just for starting posts, and had called the command startpost
. Then I realised it could solve another problem: it can be annoying to have to tab in the date when you want to edit a post you've just closed. So you can simply reopen the same file again using the same command.
Next I want to make it add the Yaml front matter at the top with the layout and title for the post.