~kris/dots

srice

ref: 512b7381d0155d6247fad64b640b0704496a8035 srice/.local/bin/note-graph -rwxr-xr-x 618 bytes
512b7381 — Kris Yotam mksh: port bashisms to mksh-safe (process subs, DEBUG-trap history hook, direnv, cd- alias) 2 months 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"