Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom bash function to generate a new markdown file for Jekyll, first arg is assumed to be post title, which becomes the filename in the format Jekyll is expecting. Auto open and save in Vim, if the post doesn't exist.
function new_post() {
cd ~/Sites/kevinquillen.com/_posts
today=$(date +"%F")
title=$1:l
clean_title=${title//[^a-zA-Z0-9]/-}
filename="$today-$clean_title.markdown"
if [[ ! -a ./$filename ]]; then
vim $filename -c 'w'
else
echo "File $filename already exists. Aborting."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment