Created
June 2, 2025 22:03
-
-
Save k12u/0fcde383f103c7386b70fb80747a08cf to your computer and use it in GitHub Desktop.
combine README.md files into a single file
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 characters
#!/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 |
Author
k12u
commented
Jun 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment