Skip to content

Instantly share code, notes, and snippets.

@kevinquillen
Last active January 8, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinquillen/307f9ec2f6e2b685c64f1bc6ce2b745c to your computer and use it in GitHub Desktop.
Save kevinquillen/307f9ec2f6e2b685c64f1bc6ce2b745c to your computer and use it in GitHub Desktop.
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