Skip to content

Instantly share code, notes, and snippets.

@k12u
Created June 2, 2025 22:03
Show Gist options
  • Save k12u/0fcde383f103c7386b70fb80747a08cf to your computer and use it in GitHub Desktop.
Save k12u/0fcde383f103c7386b70fb80747a08cf to your computer and use it in GitHub Desktop.
combine README.md files into a single file
#!/bin/bash
# Script to find and combine README.md files in a git repository
# Excludes common build/cache directories
set -euo pipefail
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: Not in a git repository" >&2
exit 1
fi
# Get the git repository root
repo_root=$(git rev-parse --show-toplevel)
# Find all README.md files, excluding specified directories
find "$repo_root" -name "README.md" -type f \
-not -path "*/.pytest_cache/*" \
-not -path "*/.venv/*" \
-not -path "*/.terraform/*" \
-not -path "*/site-packages/*" \
-not -path "*/node_modules/*" \
-not -path "*/__pycache__/*" \
-not -path "*/.git/*" \
| sort | while read -r readme_file; do
# Get relative path from repository root
relative_path=${readme_file#"$repo_root/"}
# Handle case where file is in repo root
if [ "$relative_path" = "$readme_file" ]; then
relative_path=$(basename "$readme_file")
fi
# Output filename as heading
echo "# $relative_path"
echo
# Process content: add one '#' to each heading line
sed 's/^#/##/' "$readme_file"
echo
echo
done
@k12u
Copy link
Author

k12u commented Jun 3, 2025

repomix --include "**/README.md" --ignore "node_modules/,**/.terraform/,**/.venv/,**/.pytest_cache/,**/target/,**/build/,**/dist/" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment