summaryrefslogtreecommitdiff
path: root/bin/extra/notes_index
diff options
context:
space:
mode:
Diffstat (limited to 'bin/extra/notes_index')
-rwxr-xr-xbin/extra/notes_index40
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/extra/notes_index b/bin/extra/notes_index
new file mode 100755
index 0000000..9ccb3b2
--- /dev/null
+++ b/bin/extra/notes_index
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+NOTES="$HOME"/notes
+
+if ! [ -d "$NOTES" ]; then
+ >&2 printf 'No notes directory.\n'
+ exit 1
+fi
+
+cd "$NOTES"
+
+find . -type d | while read -r d
+do
+ cd "$d"
+ printf '# Notes\n' > index.md
+ find . \
+ -maxdepth 1 \
+ -type f \
+ -name '*.md' \
+ -not \
+ -name 'index.md' \
+ -printf '%f ' \
+ -exec grep '^# ' -m1 {} \; |
+ sed 's/\(.\+\.md\) # \(.\+\)/- [\2](\1)/' |
+ sort -t '[' -k 2 >> index.md
+
+ if [ "$(find . -mindepth 2 -maxdepth 2 -type f -name '*.md' | wc -l)" -gt 0 ]
+ then
+ printf '# Dirs\n' >> index.md
+ find . \
+ -mindepth 1 \
+ -maxdepth 1 \
+ -type d \
+ -not -name '.*'\
+ -printf '- [%f](%f/index.md)\n' |
+ sort -t '[' -k 2 >> index.md
+ fi
+
+ cd - > /dev/null
+done