Skip to content

Instantly share code, notes, and snippets.

@panchicore
Last active February 21, 2025 13:37
Show Gist options
  • Save panchicore/624e33104590465fbb91a8aad7c8c1f6 to your computer and use it in GitHub Desktop.
Save panchicore/624e33104590465fbb91a8aad7c8c1f6 to your computer and use it in GitHub Desktop.

aggregate_code.sh

A command-line utility to consolidate your code files for AI code reviews

How to Use

  1. Make the script executable

    chmod +x aggregate_code.sh
  2. Run it with a required directory path

    ./aggregate_code.sh -d /Users/panchicore/code/frontend/src/components/WorkflowManagerModal
  3. Specify a different output file

    ./aggregate_code.sh -d /my/project -o /tmp/my_review.txt
  4. Customize the file extensions

    ./aggregate_code.sh -d /my/project -e "ts,tsx"

#!/bin/bash
# Default values
OUTPUT_FILE="./aggregated_code_review.txt"
EXTENSIONS="jsx,js,tsx,ts"
# Function to show usage
usage() {
echo "Usage: $0 -d <directory> [-o <output_file>] [-e <extensions>]"
echo " -d Directory to search (required)"
echo " -o Output file path (default: $OUTPUT_FILE)"
echo " -e File extensions to search (comma-separated, default: $EXTENSIONS)"
exit 1
}
# Parse arguments
while getopts "d:o:e:" opt; do
case "$opt" in
d) SEARCH_DIR="$OPTARG" ;;
o) OUTPUT_FILE="$OPTARG" ;;
e) EXTENSIONS="$OPTARG" ;;
*) usage ;;
esac
done
# Check if directory was provided
if [ -z "$SEARCH_DIR" ]; then
echo "Error: Directory is required."
usage
fi
# Convert comma-separated extensions to `-o` options for `find`
EXT_PATTERN=$(echo "$EXTENSIONS" | sed 's/,/ -o -name *./g')
EXT_PATTERN="-name *.$EXT_PATTERN"
# Clear or create the output file
> "$OUTPUT_FILE"
# Find and concatenate files
find "$SEARCH_DIR" -type f \( $EXT_PATTERN \) | while read -r file; do
echo -e "\n=== $file ===\n" >> "$OUTPUT_FILE"
cat "$file" >> "$OUTPUT_FILE"
done
echo "Aggregation complete. Output saved to $OUTPUT_FILE."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment