Jump to the navigation menu

My `create-note` script

This is my create-note script.

Written in Bash, I can enter a note title when executing the command or I am prompted to type one.

The title is used to generate a slug that is used for the filename as well as being displayed in a front-matter section along with the date and slug.

A temporary file is created from a template and opened in Neovim for me to edit.

If I make changes and save the file, a permanent copy is saved in my current directory.

#!/usr/bin/env bash

set -euo pipefail

export PATH="$PATH"

if [ -z "${1:-}" ]; then
  read -rp "Title: " title
else
  title="$*"
fi

stopwords="a|an|and|by|on|or|to|vs|with"

clean_title=$(echo "$title" \
  | sed -E "s/\b($stopwords)\b//Ig" \
  | sed -E 's/  +/ /g' \
  | sed -E 's/^ | $//g')

slug=$(echo "$clean_title" \
  | tr '[:upper:]' '[:lower:]' \
  | sed -E 's/[^a-z0-9]+/-/g' \
  | sed -E 's/^-+|-+$//g')

final_filename="${slug}.md"

date=$(date +%F)

tmpfile=$(mktemp)

template="---
title: $title
date: $date
slug: $slug
tags: []
---


"

printf "%s" "$template" > "$tmpfile"

"$EDITOR" "$tmpfile" +$ -c "set filetype=markdown" +startinsert

if ! diff -q <(printf "%s" "$template") "$tmpfile" >/dev/null; then
  mv "$tmpfile" "$final_filename"
else
  rm -f "$tmpfile"
fi

Essentially, it's the same format as creating posts on my website (like this one):

---
title: My `create-note` script
slug: create-note-script
date: 2026-03-25 20:49
tags:
  - bash
  - linux
---

This makes it quick and easy to take private notes and convert them to public blog posts in the future.