Created
January 27, 2026 18:11
-
-
Save ccorcos/163800f5065fa98aed14554e6e73882b to your computer and use it in GitHub Desktop.
Turn a repository into a flat markdown 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 | |
| # flat.sh - Concatenate files into flat.md with filenames as headers | |
| output="flat.md" | |
| > "$output" # Clear/create output file | |
| process_file() { | |
| local file="$1" | |
| if [[ -f "$file" ]]; then | |
| echo "## $file" >> "$output" | |
| echo '```' >> "$output" | |
| cat "$file" >> "$output" | |
| echo '```' >> "$output" | |
| echo "" >> "$output" | |
| fi | |
| } | |
| process_path() { | |
| local path="$1" | |
| if [[ -f "$path" ]]; then | |
| process_file "$path" | |
| elif [[ -d "$path" ]]; then | |
| while IFS= read -r -d '' file; do | |
| process_file "$file" | |
| done < <(find "$path" -type f -print0 | sort -z) | |
| else | |
| echo "Warning: '$path' not found" >&2 | |
| fi | |
| } | |
| for arg in "$@"; do | |
| process_path "$arg" | |
| done | |
| echo "Created $output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment