#!/usr/bin/env bash OUTPUT_FILE="${1:-llm_context.txt}" ROOT_DIR="${2:-.}" # Absolute Pfade auflösen OUTPUT_PATH="$(cd "$(dirname "$OUTPUT_FILE")" 2>/dev/null && pwd)/$(basename "$OUTPUT_FILE")" cd "$ROOT_DIR" || exit 1 # Ausgabedatei initialisieren / leeren > "$OUTPUT_PATH" echo "========================================" >> "$OUTPUT_PATH" echo "PROJEKTSTRUKTUR" >> "$OUTPUT_PATH" echo "========================================" >> "$OUTPUT_PATH" # Prüfen, ob Git verfügbar und das Verzeichnis ein Git-Repo ist IS_GIT_REPO=false if command -v git &> /dev/null && git rev-parse --is-inside-work-tree &> /dev/null; then IS_GIT_REPO=true fi if [ "$IS_GIT_REPO" = true ]; then echo "(Ermittelt via Git unter Berücksichtigung von .gitignore)" >> "$OUTPUT_PATH" # Zeigt alle getrackten + ungetrackten Dateien an, ignoriert .gitignore-Treffer git ls-files -co --exclude-standard >> "$OUTPUT_PATH" else if command -v tree &> /dev/null; then tree -I 'node_modules|.git|venv|.venv|__pycache__|dist|build|.next|target' >> "$OUTPUT_PATH" else find . -maxdepth 3 -not -path '*/.*' -not -path '*/node_modules*' -not -path '*/venv*' >> "$OUTPUT_PATH" fi fi echo -e "\n========================================" >> "$OUTPUT_PATH" echo "DATEIINHALTE" >> "$OUTPUT_PATH" echo "========================================" >> "$OUTPUT_PATH" # Dateiliste ermitteln get_file_list() { if [ "$IS_GIT_REPO" = true ]; then # -c = cached/tracked, -o = others/untracked, --exclude-standard = .gitignore beachten git ls-files -co --exclude-standard else find . -type f \ -not -path '*/.git/*' \ -not -path '*/node_modules/*' \ -not -path '*/venv/*' \ -not -path '*/.venv/*' \ -not -path '*/__pycache__/*' \ -not -path '*/dist/*' \ -not -path '*/build/*' \ -not -path '*/.next/*' fi } # Dateien verarbeiten get_file_list | sort | while IFS= read -r file; do # Überspringe leere Pfade, die Zieldatei selbst oder typische Binär-Endungen [ -z "$file" ] && continue [ "$file" = "$OUTPUT_FILE" ] && continue [ "$(realpath "$file" 2>/dev/null)" = "$OUTPUT_PATH" ] && continue case "$file" in *.png|*.jpg|*.jpeg|*.gif|*.ico|*.pdf|*.zip|*.tar.gz|*.lock|package-lock.json|yarn.lock) continue ;; esac # Prüfen, ob die Datei existiert und lesbarer Text ist if [ -f "$file" ] && (grep -Iq . "$file" 2>/dev/null || [ ! -s "$file" ]); then echo -e "\n--- DATEI: $file ---" >> "$OUTPUT_PATH" echo '```' >> "$OUTPUT_PATH" cat "$file" >> "$OUTPUT_PATH" echo -e "\n"'```' >> "$OUTPUT_PATH" fi done echo "Fertig! Projektkontext liegt in: $OUTPUT_PATH"