Created
April 12, 2025 21:03
-
-
Save krishvishal/c6cfe05cdfe6cd6d801f38234f9a8aca to your computer and use it in GitHub Desktop.
Revisions
-
krishvishal created this gist
Apr 12, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!/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 <root_dir> <extension_without_dot> <output_file>" 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<n; i++) printf "β "; if (NR==1 || last_depth < n) printf "βββ "; else printf "βββ "; print parts[n]; last_depth = n; }' >> "$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"