Skip to content

Instantly share code, notes, and snippets.

@monkpit
Last active July 30, 2021 16:59
Show Gist options
  • Save monkpit/a1709899ce633a0e383c9214c2f838df to your computer and use it in GitHub Desktop.
Save monkpit/a1709899ce633a0e383c9214c2f838df to your computer and use it in GitHub Desktop.
Build Markdown TOC for entire repo
#! /usr/bin/env bash
# Made to work on Mac version of `stat`
rm -f readme.md
# Static header contents go in readme.header.md
cat readme.header.md >> readme.md
mdFiles=$(find ./*/ -name \*.md)
for mdFile in $mdFiles; do
# we will just take the first line that starts with "# "
# then strip off the "# " and we just assume that's a good title
title=$(sed -n "s/^# \(.*\)/\1/p" "$mdFile")
updated=$(stat -f "%Sm" "$mdFile")
printf "* [%s](%s) - updated %s\n" "$title" "$mdFile" "$updated" >> readme.md
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment