Skip to main content
  1. Posts/

Creating TILs from the Command Line with Hugo

·280 words·2 mins·
Table of Contents

I like removing friction wherever I can, especially for things I do often. The kind of small, repeatable workflows that quietly eat time if you let them.

Creating TIL posts is one of those workflows. I want to:

  • run a command
  • have the file created correctly
  • open it immediately
  • start writing

With Hugo, the clean way to do this is by leaning on archetypes instead of trying to outsmart the framework.


Step 1: Define a TIL Archetype
#

Create:

archetypes/til.md
+++
title = "{{ replace .Name "-" " " | title }}"
date = {{ .Date }}
tags = ["TIL"]
draft = true
+++

Now every new TIL starts with consistent frontmatter, no extra work required.


Step 2: Simple CLI Script
#

Here’s a small script to generate a TIL from anywhere:

#!/usr/bin/env bash

set -euo pipefail

SITE_DIR="$HOME/<Site Directory...>" # Replace with your Hugo site
EDITOR_CMD="code" # VS Code for me—swap this for vim, nvim, etc.
TITLE="${*:-}"

if [[ -z "$TITLE" ]]; then
  echo "Usage: til <title>"
  exit 1
fi

cd "$SITE_DIR"

SLUG=$(printf '%s' "$TITLE" \
  | tr '[:upper:]' '[:lower:]' \
  | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')

FILE_PATH="content/til/${SLUG}.md"

hugo new "$FILE_PATH"

"$EDITOR_CMD" "$FILE_PATH"
hugo server -D

Usage
#

Drop the til script somewhere in your PATH, then make it executable:

chmod +x til

Now you can create a new TIL from any directory with:

til My new til title

That’s it. File created, editor open, server running.


Why This Works
#

  • Hugo handles structure via archetypes
  • The script handles speed and convenience

No duplication. No maintenance overhead. Just a clean workflow.

Small win, but these stack up fast. Less friction means more writing, and more writing is the whole game.

Chandler Thompson
Author
Chandler Thompson
Perpetual Hobbyist.

Related