Last Updated: February 25, 2016
· kuroir

GitHub Wiki: Table of Contents

As soon as I began using GitHub Wiki's seriously, I noticed that there's no easy way to generate a Table of Contents, based on a list of files within a directory.

When making a new GitHub Wiki, usually what I do is go into command line and begin creating empty files, which are basically placeholders for stuff I need to work on.

You're probably wondering: But Mario, why don't you just do [[SomethingThatDoesntExist]]? That'll highlight it as red (nonexistent).

The reason for that, is that it means I need to manually keep track of the Contents of the directory, and I need to update the files manually. Who has time for that? I don't.

So lets say we have the following Directory structure:

Where SomeSubject contains all the files you want to have in the Table of Contents and the file is the file that will contain teh Table of Contents.

TOC="SomeSubject"; ls -l $TOC | awk 'NF >= 7 { sub(/\.md/, "", $9); sub(/\-/, " ", $9); printf("* [[%s]]%s\n", $9, ($5 == 0) ? " (PENDING)" : ""); }' > $

That command will generate the following:

* [[1. Interesting Subject]] (PENDING)
* [[2. Interesting Subject]] (PENDING)
* [[3. Interesting Subject]] (PENDING)

As you can see, at the end (PENDING) is added. This is a flag that states that the file is empty ( 0 bydes ).

And there you have it, an easy way to do a Table of Contents on GitHub Wikis.