diff options
Diffstat (limited to 'tools/link_toolchain.sh')
| -rw-r--r-- | tools/link_toolchain.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/link_toolchain.sh b/tools/link_toolchain.sh new file mode 100644 index 0000000..8f488e1 --- /dev/null +++ b/tools/link_toolchain.sh @@ -0,0 +1,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" |
