Skip to content

CLI tool to copy all code in a project into a text file for easy upload to AI for analysis

License

Notifications You must be signed in to change notification settings

forrest321/code2text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code2text

Introduction

code2text is a CLI tool designed to walk through directories, collect code files based on specified filters, and consolidate their contents into a single text document. This tool is particularly useful for gathering code for analysis or archiving.

Installation

Download Executable

Find the compiled executable for your OS and arch on the releases page

Prerequisites

  • Go (1.15 or later)

Install with Go

go install github.com/forrest321/code2text

Build from Source

  1. Clone the repository:
    git clone https://github.com/forrest321/code2text
  2. Navigate to the project directory:
    cd code2text
  3. Build the tool:
    go build -o code2text
  4. Move the created binary to a location within your PATH
    sudo mv code2text /usr/bin/

Usage

Run the tool using the following syntax:

If using code2text installed in path:

code2text [flags]

If using locally created code2text binary in the same folder:

./code2text [flags]

Defaults

IncludeExtensions: []string{".go", ".js", ".jsx", ".ts", ".tsx", ".py", ".rb", ".php", ".swift", ".c", ".cpp", ".h", ".hpp", ".java", ".rs", ".kt", ".scala", ".m"},
ExcludeExtensions: []string{".log", ".tmp", ".bak", ".o", ".obj", ".class", ".exe", ".dll", ".so", ".a", ".lib", ".pyc", ".jar"},
IgnoreDirs:        []string{".git", ".idea", ".vscode", "node_modules", "vendor", "build", "dist", "bin", "obj"},
OutputFile:        "output.txt"

Flags

  • -o, --output <file>: Specify the output file name (default is output.txt).
  • -i, --include <extensions>: Specify file extensions to include (default includes .go, .js).
  • -e, --exclude <extensions>: Specify file extensions to exclude.
  • -g, --ignore <directories>: Specify directories to ignore (default ignores .git, .idea).

Example

If using code2text installed in path:

code2text --output result.txt --include .go --include .js --exclude .test --ignore .git

If using locally created code2text binary in the same folder:

./code2text --output result.txt --include .go --include .js --exclude .test --ignore .git

Output Details

The output file begins with the directory structure, followed by the content of each file included in the scan. Each file's content is clearly separated and includes metadata about the file path and the number of lines.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

CLI tool to copy all code in a project into a text file for easy upload to AI for analysis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages