~kris/dots

srice

ref: 9f828eb14bdd54d2c4fd8a3b2c90253021df3152 srice/.local/bin/note-graph -rwxr-xr-x 618 bytes
9f828eb1 — Kris Yotam mksh: backslash-escape commands in history hook to bypass module aliases (wc=tokei, tr=transmission-remote, cat=bat) 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"