Image of Austin Gatlin's face
March 14, 2022

Shell Script for Creating Markdown Templates

For my Next.js blog I want to be able to create notes quickly. I've setup a shell script (bash, zsh, etc) to quickly create a markdown file prepopulated with basic content I pass in as parameters.

A couple notes regarding what you are about to read

  • gn is short for gatlin-note, and gatlin is the name of the (private) repo.
  • ~/w/g/gatlin is the location of the repo on my local machine.
  • content/notes/*.md is where I keep my markdown notes files.
  • I parse yaml metadata located at the top of my markdown files.
  • After prepopulating the Markdown file, I open it up immediately in vim to make edits quickly.
  • If you are going to rip parts of this function, note that I have only used this script in zsh.
  • Example usage:
    gn "New Note" new-note
function gn() {
  cd ~/w/g/gatlin
  local filename="./content/notes/$"
  local datestring="$(date +%F)"
  touch $filename
  cat << DELIMIT > $filename
title: $1
slug: $2
published: $datestring
updated: $datestring

# $1


  vim $filename