A shell script to consolidate a source code repository into a single, well-structured Markdown file. This is useful for passing the entire context of a project to a Large Language Model (LLM), for code reviews, or for creating a comprehensive project archive.
The script can process a local directory or clone a remote Git repository. It intelligently excludes common unnecessary files and directories, and can be customized to include specific file types or add more exclusions.
./repo-exporter.sh <path_or_url> [OPTIONS]
<path_or_url>
: Required. The path to a local source code directory or the URL of a remote Git repository. For remote repositories, you can specify a tag or commit by appending@tag_or_commit
to the URL.
-o <output_file>
: Optional. The name of the output Markdown file.- Default:
export.md
- Default:
-e <extensions>
: Optional. A comma-separated list of file extensions to include in the export.- Default: A comprehensive list of common programming and configuration file extensions.
-x <exclude_patterns>
: Optional. A comma-separated list of patterns to exclude from the export. These are added to the default exclusion list.- Default exclusions:
*/.git/*
,*/node_modules/*
,*/dist/*
,*/build/*
,*/.vscode/*
,*/.idea/*
,*.log
,*.lock
- Default exclusions:
-h
,--help
: Show the help message and exit.
This will scan the ~/projects/my-cool-app
directory and create a file named export.md
in your current directory.
./repo-exporter.sh ~/projects/my-cool-app
This will scan the ~/projects/my-cool-app
directory and create a file named my-cool-app-export.md
.
./repo-exporter.sh ~/projects/my-cool-app -o my-cool-app-export.md
The script will clone the specified repository into a temporary directory, export its contents to export.md
, and then ask if you want to delete the temporary directory.
./repo-exporter.sh https://github.com/user/repo.git
This example overrides the default list of extensions to only include .py
and .md
files.
./repo-exporter.sh ~/projects/my-python-project -e py,md
In addition to the default exclusions, this will also ignore any backups
directory.
./repo-exporter.sh ~/projects/my-cool-app -x "*/backups/*"
This example clones a specific tag (v1.0.0) from a GitHub repository and exports its contents.
./repo-exporter.sh https://github.com/user/[email protected]
You can also specify a commit hash:
./repo-exporter.sh https://github.com/user/repo.git@abc123def456
This works with SSH URLs as well:
./repo-exporter.sh [email protected]:user/[email protected]