~kris/dots

srice

srice/.local/bin/note-graph -rw-r--r-- 618 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash
# note-graph -- generate link graph from [[wikilink]] notes
# Usage: note-graph [notes_dir] [output.dot]
set -euo pipefail
notes_dir="${1:-$HOME/notes}"
output="${2:-/dev/stdout}"

echo "digraph notes {" > "$output"
echo '  rankdir=LR;' >> "$output"
echo '  node [shape=box, style=rounded, fontname="monospace"];' >> "$output"

for f in "$notes_dir"/*.md; do
    [ -f "$f" ] || continue
    src=$(basename "$f" .md)
    grep -oP '\[\[([^\]|]+)' "$f" 2>/dev/null | sed 's/\[\[//' | while read -r target; do
        echo "  \"$src\" -> \"$target\";" >> "$output"
    done
done

echo "}" >> "$output"