blob: 8f488e1b4ac9703b22e745f492ef75e55ef0da4e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/sh
# Link the toolchain's notes into your repo's knowledge graph, one symlink per file (IWE and
# other Markdown tools follow file symlinks, not directory symlinks).
#
# sh toolchain/tools/link_toolchain.sh [TOOLCHAIN_DIR] [--topics name ...]
#
# Run from your repo root. Links every knowledge/tooling/*.md of the toolchain into
# knowledge/tooling/, and the topics named after --topics (default: all) into knowledge/topics/.
# Existing regular files are left alone and reported; stale links into the toolchain are removed.
set -e
TC=${1:-toolchain}; [ $# -gt 0 ] && shift
[ -d "$TC/knowledge/tooling" ] || { echo "no $TC/knowledge/tooling; pass the toolchain directory" >&2; exit 1; }
TOPICS=""
if [ "$1" = "--topics" ]; then shift; TOPICS="$*"; fi
[ -n "$TOPICS" ] || TOPICS=$(cd "$TC/knowledge/topics" && ls *.md | sed 's/\.md$//')
link() { # link SUBDIR NAME
mkdir -p "knowledge/$1"
dst="knowledge/$1/$2.md"
if [ -e "$dst" ] && [ ! -L "$dst" ]; then echo "kept (own file): $dst"; return; fi
ln -sfn "../../$TC/knowledge/$1/$2.md" "$dst"
}
for f in "$TC"/knowledge/tooling/*.md; do link tooling "$(basename "$f" .md)"; done
for t in $TOPICS; do link topics "$t"; done
for d in knowledge/tooling knowledge/topics; do
for l in "$d"/*.md; do [ -L "$l" ] && [ ! -e "$l" ] && { rm "$l"; echo "removed stale link: $l"; }; done
done
echo "linked $(ls "$TC"/knowledge/tooling/*.md | wc -l | tr -d ' ') tool notes"
|