testsAndMisc/linux_configuration/utils/repo_to_study.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

161 lines
4.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#==============================================================================
# repo_to_study.sh - Complete pipeline: Repo → Analysis → Offline Docs → Study Materials
#
# Usage:
# repo_to_study.sh <repo_url_or_path>
#
# Examples:
# repo_to_study.sh https://github.com/user/repo
# repo_to_study.sh /path/to/local/repo
# repo_to_study.sh .
#
# Output:
# Creates study materials in ~/.local/share/study-materials/<repo_name>/
# - documentation_links.md (with offline doc paths)
# - anki_cards.txt (importable to Anki)
# - llm_anki_prompt.md (for generating more cards with AI)
#==============================================================================
set -euo pipefail
# Script directory for finding other tools
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ANALYZE_SCRIPT="$SCRIPT_DIR/analyze_repo.sh"
STUDY_SCRIPT="$SCRIPT_DIR/generate_study_materials.sh"
SETUP_DOCS_SCRIPT="$SCRIPT_DIR/setup_offline_docs.sh"
# Default output location (not in script dir, user's data dir)
STUDY_MATERIALS_BASE="$HOME/.local/share/study-materials"
# Work directories
WORK_DIR="/tmp/repo_study_$$"
# shellcheck disable=SC2034 # OUTPUT_DIR set dynamically by parse_args
OUTPUT_DIR=""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
#==============================================================================
# Helper Functions (all print to stderr to not interfere with return values)
#==============================================================================
print_header() {
echo -e "\n${BOLD}${CYAN}════════════════════════════════════════════════════════════${NC}" >&2
echo -e "${BOLD}${CYAN} $1${NC}" >&2
echo -e "${BOLD}${CYAN}════════════════════════════════════════════════════════════${NC}\n" >&2
}
print_step() {
echo -e "${BOLD}${BLUE}▶ $1${NC}" >&2
}
print_success() {
echo -e "${GREEN}✓ $1${NC}" >&2
}
print_error() {
echo -e "${RED}✗ $1${NC}" >&2
}
print_info() {
echo -e "${YELLOW}→ $1${NC}" >&2
}
cleanup() {
if [ -d "$WORK_DIR" ] && [ "$WORK_DIR" != "/" ]; then
rm -rf "$WORK_DIR"
fi
}
trap cleanup EXIT
usage() {
cat <<EOF
repo_to_study.sh - Generate study materials from any repository
USAGE:
$(basename "$0") <repo_url_or_path> [output_dir]
ARGUMENTS:
repo_url_or_path Git URL (https/ssh) or local path to repository
output_dir Optional: where to save results
Default: ~/.local/share/study-materials/<repo_name>/
EXAMPLES:
$(basename "$0") https://github.com/python/cpython
$(basename "$0") git@github.com:torvalds/linux.git
$(basename "$0") /home/user/my-project
$(basename "$0") . ~/notes/my_study_notes
OUTPUT FILES:
documentation_links.md - Markdown with offline documentation links
anki_cards.txt - Tab-separated file for Anki import
llm_anki_prompt.md - Prompt template for AI-generated cards
analysis/ - Raw analysis data (imports, keywords, functions)
EOF
exit 0
}
# shellcheck source=lib/repo_study_steps.sh
source "$SCRIPT_DIR/lib/repo_study_steps.sh"
main() {
# Handle help
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
fi
local input="$1"
local output_dir="${2:-}" # Will be set after we know repo name
print_header "Repo → Study Materials Pipeline"
# Setup
mkdir -p "$WORK_DIR"
check_dependencies
ensure_offline_docs
# Step 1: Get repository
print_header "Step 1/3: Getting Repository"
local repo_path
repo_path=$(get_repo "$input")
# Extract repo name from path (since get_repo runs in subshell, REPO_NAME is lost)
if [ -z "$REPO_NAME" ]; then
REPO_NAME=$(basename "$repo_path")
fi
# Set default output dir based on repo name
if [ -z "$output_dir" ]; then
output_dir="$STUDY_MATERIALS_BASE/$REPO_NAME"
elif [[ $output_dir != /* ]]; then
# Convert relative to absolute
output_dir="$(pwd)/$output_dir"
fi
echo -e "${BOLD}Input:${NC} $input" >&2
echo -e "${BOLD}Output:${NC} $output_dir" >&2
echo "" >&2
# Step 2: Analyze
print_header "Step 2/3: Analyzing Code"
local analysis_dir
analysis_dir=$(analyze_repo "$repo_path")
# Step 3: Generate materials
print_header "Step 3/3: Generating Study Materials"
generate_materials "$analysis_dir" "$output_dir"
# Show results
show_summary "$output_dir"
}
main "$@"