Skip to content

Instantly share code, notes, and snippets.

@panchicore
Last active February 21, 2025 13:37
Show Gist options
  • Select an option

  • Save panchicore/624e33104590465fbb91a8aad7c8c1f6 to your computer and use it in GitHub Desktop.

Select an option

Save panchicore/624e33104590465fbb91a8aad7c8c1f6 to your computer and use it in GitHub Desktop.

Revisions

  1. panchicore revised this gist Feb 21, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion a_aggregate_code_readme.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ A command-line utility to consolidate your code files for AI code reviews

    4. **Customize the file extensions**
    ```bash
    ./aggregate_code.sh -d /my/project -e "js,ts,jsx"
    ./aggregate_code.sh -d /my/project -e "ts,tsx"
    ```

    ---
  2. panchicore renamed this gist Feb 21, 2025. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion a_readme.md → a_aggregate_code_readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@

    # aggregate_code.sh
    A command-line utility to consolidate your code files for AI code reviews

    ### **How to Use**
    1. **Make the script executable**
  3. panchicore created this gist Feb 21, 2025.
    24 changes: 24 additions & 0 deletions a_readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@


    ### **How to Use**
    1. **Make the script executable**
    ```bash
    chmod +x aggregate_code.sh
    ```

    2. **Run it with a required directory path**
    ```bash
    ./aggregate_code.sh -d /Users/panchicore/code/frontend/src/components/WorkflowManagerModal
    ```

    3. **Specify a different output file**
    ```bash
    ./aggregate_code.sh -d /my/project -o /tmp/my_review.txt
    ```

    4. **Customize the file extensions**
    ```bash
    ./aggregate_code.sh -d /my/project -e "js,ts,jsx"
    ```

    ---
    45 changes: 45 additions & 0 deletions aggregate_code.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/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."