#!/bin/bash # Usage: ./collect_sources.sh /path/to/dir rs output.txt ROOT_DIR="$1" EXT="$2" OUTPUT="$3" if [[ -z "$ROOT_DIR" || -z "$EXT" || -z "$OUTPUT" ]]; then echo "Usage: $0 " exit 1 fi # Create or clear the output file > "$OUTPUT" # Add file tree to the output echo "📁 File Tree:" >> "$OUTPUT" find "$ROOT_DIR" -type f -name "*.$EXT" | sed "s|$ROOT_DIR/||" | awk '{ n=split($0, parts, "/"); for (i=1; i> "$OUTPUT" echo "" >> "$OUTPUT" # Recursively add files with updated delimiters find "$ROOT_DIR" -type f -name "*.$EXT" | while read -r file; do echo "------ begin $file ------" >> "$OUTPUT" cat "$file" >> "$OUTPUT" echo "------ end $file ------" >> "$OUTPUT" echo "" >> "$OUTPUT" done echo "✅ Done. Output written to $OUTPUT"