Advertisement
crzyc

generate_context.sh

Dec 22nd, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.81 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Path to the Python virtual environment's Python executable (adjust if needed)
  4. PYTHON_EXEC="python"
  5.  
  6. # Path to the code_context.py script (relative to the script's location)
  7. SCRIPT_PATH="./code_context.py"  # Assuming script and code_context.py are in the same directory
  8.  
  9. # Directory to process (passed as first argument)
  10. TARGET_DIRECTORY="$1"
  11.  
  12. # Output file
  13. OUTPUT_FILE="output.txt"
  14.  
  15. # Define folders and files to exclude
  16. EXCLUDES=(
  17.     "venv/"          # Exclude virtual environment directory
  18.     ".git/"          # Exclude Git metadata
  19.     "__pycache__/"   # Exclude Python cache files
  20.     "build/"         # Exclude build artifacts
  21.     "dist/"          # Exclude distribution artifacts
  22.     "*.egg-info/"    # Exclude package metadata
  23.     ".idea/"         # Exclude IDE metadata
  24.     ".vscode/"       # Exclude VSCode metadata
  25.     "*.swp"          # Exclude temporary files
  26.     "*.swo"          # Exclude temporary files
  27.     ".DS_Store"      # Exclude macOS system file
  28. )
  29.  
  30. # Create the `rsync`-compatible exclude list
  31. EXCLUDE_PARAMS=()
  32. for EXCLUDE in "${EXCLUDES[@]}"; do
  33.     EXCLUDE_PARAMS+=(--exclude="$EXCLUDE")
  34. done
  35.  
  36. # Use rsync to copy only relevant files into a filtered directory
  37. FILTERED_DIR="./filtered_directory"
  38. mkdir -p "$FILTERED_DIR"
  39. echo "Filtering files into $FILTERED_DIR..."
  40. rsync -a "${EXCLUDE_PARAMS[@]}" --include="*/" --include="*.py" --exclude="*" "$TARGET_DIRECTORY" "$FILTERED_DIR"
  41.  
  42. # Run the Python script to combine files in the filtered directory
  43. echo "Running Python script..."
  44. $PYTHON_EXEC $SCRIPT_PATH "$FILTERED_DIR" -o "$OUTPUT_FILE"
  45.  
  46. # Notify user
  47. if [ $? -eq 0 ]; then
  48.     echo "Context generated successfully. Output saved to $OUTPUT_FILE."
  49. else
  50.     echo "Failed to generate context. Please check for errors."
  51. fi
  52.  
  53. # Cleanup
  54. rm -rf "$FILTERED_DIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement