concreat, A Bash Script for Creating Markdown Files for Concerts I’ve Attended
I’ve been to dozens of concerts over the years. I decided to start documenting and cataloging them on justwherefar. I doubt that I’ll ever have 100% completion or accuracy, but it’s been a fun exercise digging through old photos, receipts, and ticket stubs. I’m considering making a custom landing page for them, but for now you can find them all linked at the concerts tag page.
I made a bash script to help easily create these posts as Markdown files, which Blot will later turn into posts. I’ve aliased it as concreat, short for “concert creator”, sounds like “concrete”.
This input…
concreat -a glassJAw -g hardcore -d 2006-12-29 -v "Webster Hall, New York, NY"
…creates a file named 2006-12-29-glassjaw.md with these contents…
title: glassJAw
tags: glassJAw, hardcore
date: 2006-12-29
venue: Webster Hall, New York, NY
link: 2006-12-29-glassjaw
### Setlist
The script is below.
#!/bin/bash
# declare some variables
OPTSTRING=":a:g:d:v:"
ARTIST=""
ARTIST_LOWERCASE=""
GENRE=""
DATE=""
VENUE=""
LINK=""
while getopts ${OPTSTRING} opt; do
case ${opt} in
# save the -a argument as the artist
# then save the artist name in all lowercase as a separate variable
a)
ARTIST=${OPTARG}
ARTIST_LOWERCASE=$(echo "$ARTIST" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
;;
# save the -g argument as the genre
g)
GENRE=", ${OPTARG}"
;;
# save the -d argument as the date
# since the date is used as part of the filename,
# this expects ISO 8601 format, YYYY-MM-DD
d)
DATE=${OPTARG}
;;
# save the -v argument as the venue
v)
VENUE=${OPTARG}
;;
# complain if no option is specified
:)
echo "Option -${OPTARG} requires an argument."
exit 1
;;
# complain if an invalid option is specified
?)
echo "Invalid option: -${OPTARG}."
exit 1
;;
esac
done
# save the URL slug as YYYY-MM-DD-artist
# this will also be used as the filename later
LINK=$DATE-$ARTIST_LOWERCASE
# create a Markdown file with the needed metadata at the top
# include an h2 level Setlist heading, since most posts will have one
# save it as YYYY-MM-DD-artist.md
echo "title: $ARTIST
tags: $ARTIST$GENRE
date: $DATE
venue: $VENUE
link: $LINK
### Setlist" > $DATE-$ARTIST_LOWERCASE.md
# open the file for editing
open $DATE-$ARTIST_LOWERCASE.md