date
in bashPublished May 30, 2025
I decided to put together a Justfile for helping me out here. One of the things I wanted it for was to help me add new TIL
and blog posts. Adding one of these generally is a CLI call to the render-engine
tool. It looks something like this:
render-engine new-entry <filename> [arguments]
Since I'm lazy I don't want to have to type all of the arguments in myself so I want something where I can just call Just and have it fill in the blanks with some defaults. So I wrote a couple of recipes for it:
til title filename=(FNDATE):
render-engine new-entry {{ filename }} --collection til --include-date --title "{{ title }}" --slug {{ DATE }}
blog title filename=(FNDATE):
render-engine new-entry {{ filename }} --collection blog --include-date --title "{{ title }}"
You might notice that there are some variables in there. And that's the part where I wanted the automation to really help. I didn't want to type in the date - and definitely not in 2 different formats - so I tried to use some shell completion to get it done. That's when I realized I knew less about using bash to get the date in the format I need than I wanted to.
For the slug
(that's the part of the URL that specifies this specific post) I wanted a format like 20250530
but I wanted something a bit more human readable for the filename that I'm actually going to edit, may302025
. With some
search foo I was able to find what I needed to get it done:
DATE := `date '+%Y%m%d'`
FNDATE := `echo $(date '+%b%d%Y' | tr '[:upper:]' '[:lower:]').md`
This gives me 2 variables DATE
, and FNDATE
that serve for the slug and the filename. You'll notice that I can
override the filename
(which I usually want to do with blog posts) and that I only use the slug
for the TIL ones.
That's mostly because the TIL are date specific while the blog posts I want a more unique URL for. After all, I can publish more than one
blog post on any given day.