|
1 | 1 | # PathDigest |
2 | 2 |
|
3 | | -PathDigest is a command-line tool written in Go that analyzes Git repositories, local directories, or individual files and generates a structured, LLM-friendly text digest of their content. This digest can be easily used as context for Large Language Models (LLMs) in tools like Cursor, VSCode, Gemini, and others. |
| 3 | +PathDigest is a command-line tool written in Go that analyzes Git repositories, local directories, or individual files and generates a structured, LLM-friendly text digest of their content. The digest can be used as context for Large Language Models (LLMs) in tools like Cursor, VSCode, Gemini, and others. |
4 | 4 |
|
5 | 5 | Inspired by web-based tools like [gitingest](https://github.com/cyclotruc/gitingest) by @cyclotruc, PathDigest brings similar powerful code-to-context capabilities directly to your terminal as a native, efficient binary. |
6 | 6 |
|
7 | | -> I made this tool for my own use, but I thought it might be useful for others. |
| 7 | +> I made this tool for my own use, but I thought it might be useful to others. |
8 | 8 |
|
9 | 9 | ## Installation |
10 | 10 |
|
11 | | -### Via `go install` (Recommended if you have Go installed) |
| 11 | +### Via `go install` (requires Go 1.23+) |
12 | 12 |
|
13 | | -Make sure you have Go (1.20 or higher recommended) installed and `$HOME/go/bin` (or `$GOPATH/bin`) is in your `PATH`. |
| 13 | +Make sure `$HOME/go/bin` (or `$GOPATH/bin`) is in your `PATH`. |
14 | 14 |
|
15 | 15 | ```bash |
16 | 16 | go install github.com/ga1az/pathdigest@latest |
17 | 17 | ``` |
18 | 18 |
|
19 | | -### Via `install.sh` (Recommended if you don't have Go installed) |
| 19 | +### Via install script (macOS & Linux) |
20 | 20 |
|
21 | 21 | ```bash |
| 22 | +# Install to default directory ($GOPATH/bin or ./bin) |
22 | 23 | curl -sSfL https://raw.githubusercontent.com/ga1az/pathdigest/main/install.sh | sh -s |
23 | 24 |
|
24 | 25 | # Install to a specific directory |
25 | 26 | curl -sSfL https://raw.githubusercontent.com/ga1az/pathdigest/main/install.sh | sh -s -- -b /usr/local/bin |
| 27 | + |
| 28 | +# Install a specific version |
| 29 | +curl -sSfL https://raw.githubusercontent.com/ga1az/pathdigest/main/install.sh | sh -s -- v0.2.0 |
| 30 | +``` |
| 31 | + |
| 32 | +### Via GitHub Releases |
| 33 | + |
| 34 | +Download the binary for your platform from [github.com/ga1az/pathdigest/releases](https://github.com/ga1az/pathdigest/releases). |
| 35 | + |
| 36 | +```bash |
| 37 | +# macOS (Apple Silicon) |
| 38 | +curl -sL https://github.com/ga1az/pathdigest/releases/latest/download/pathdigest_0.0.0_darwin_arm64.tar.gz | tar xz |
| 39 | +chmod +x pathdigest |
| 40 | +mv pathdigest /usr/local/bin/ |
| 41 | + |
| 42 | +# macOS (Intel) |
| 43 | +curl -sL https://github.com/ga1az/pathdigest/releases/latest/download/pathdigest_0.0.0_darwin_amd64.tar.gz | tar xz |
| 44 | +chmod +x pathdigest |
| 45 | +mv pathdigest /usr/local/bin/ |
| 46 | + |
| 47 | +# Linux (amd64) |
| 48 | +curl -sL https://github.com/ga1az/pathdigest/releases/latest/download/pathdigest_0.0.0_linux_amd64.tar.gz | tar xz |
| 49 | +chmod +x pathdigest |
| 50 | +mv pathdigest /usr/local/bin/ |
| 51 | + |
| 52 | +# Linux (arm64) |
| 53 | +curl -sL https://github.com/ga1az/pathdigest/releases/latest/download/pathdigest_0.0.0_linux_arm64.tar.gz | tar xz |
| 54 | +chmod +x pathdigest |
| 55 | +mv pathdigest /usr/local/bin/ |
26 | 56 | ``` |
27 | 57 |
|
28 | 58 | ## Usage |
29 | 59 |
|
| 60 | +### Basic |
| 61 | + |
30 | 62 | ```bash |
31 | | -pathdigest <source> |
| 63 | +# Digest a local directory (outputs to pathdigest_digest.txt by default) |
| 64 | +pathdigest ./my-project |
32 | 65 |
|
33 | | -//Git URL |
| 66 | +# Digest a Git repository URL |
34 | 67 | pathdigest https://github.com/ga1az/pathdigest |
35 | 68 |
|
36 | | -//Local Directory |
37 | | -pathdigest ./projects/pathdigest -o pathdigest_digest.txt |
| 69 | +# Output to stdout (useful for piping) |
| 70 | +pathdigest ./my-project -o - |
| 71 | + |
| 72 | +# Output to a specific file |
| 73 | +pathdigest ./my-project -o digest.txt |
38 | 74 | ``` |
39 | 75 |
|
40 | | -## Features |
| 76 | +### JSON Output |
41 | 77 |
|
42 | | -* **Versatile Source Input**: Process Git repository URLs (cloning specific branches/commits if needed), local directories, or single files. |
43 | | -* **Structured Output**: Generates a clear text output including: |
44 | | - * A summary of the processed source. |
45 | | - * A tree-like representation of the directory structure. |
46 | | - * Concatenated content of all processed text files. |
47 | | -* **Customizable Filtering**: |
48 | | - * Use glob patterns to exclude specific files or directories (e.g., `*.log`, `node_modules/`). |
49 | | - * Use glob patterns to explicitly include files or directories, overriding exclusion rules. |
50 | | -* **File Size Control**: Set a maximum file size to skip very large files, keeping the context manageable. |
51 | | -* **Git Integration**: |
52 | | - * Specify a branch or commit hash when providing a Git URL. |
53 | | - * Handles different Git URL formats (HTTPS, SSH, slugs). |
54 | | -* **Go-Powered**: Built with Go for fast performance and easy cross-platform binary creation. |
| 78 | +Use `--format json` (or `-f json`) for structured output that tools and scripts can consume: |
| 79 | + |
| 80 | +```bash |
| 81 | +# JSON to file |
| 82 | +pathdigest ./my-project -f json -o digest.json |
55 | 83 |
|
| 84 | +# JSON to stdout |
| 85 | +pathdigest ./my-project -f json -o - |
56 | 86 |
|
57 | | -Output will be a json file (In progress) or txt file that can be used as a context for cursor, vscode, gemini, etc. |
| 87 | +# Default text format (unchanged behavior) |
| 88 | +pathdigest ./my-project |
| 89 | +``` |
58 | 90 |
|
59 | | -### Flags |
| 91 | +The JSON output includes: |
| 92 | +- `summary` — source path, file count, total size, patterns used |
| 93 | +- `tree` — nested directory structure with names, paths, types, sizes |
| 94 | +- `files` — flat array of all processed files with content |
| 95 | +- `git_info` — repository metadata when processing a Git URL |
60 | 96 |
|
61 | | -* `-o, --output <file_path>`: Specifies the output file path for the digest. Defaults to `pathdigest_digest.txt`. Use `-` to print to standard output. |
62 | | -* `-s, --max-size <bytes>`: Maximum file size in bytes to process (e.g., `10485760` for 10MB). Defaults to 10MB. |
63 | | -* `-e, --exclude-pattern <pattern>`: Glob pattern to exclude files/directories. Can be used multiple times. Adds to a list of default exclude patterns (e.g., `.git/`, `node_modules/`). |
64 | | -* `-i, --include-pattern <pattern>`: Glob pattern to include files/directories. Can be used multiple times. If include patterns are provided, only files matching these patterns will be processed (overriding excludes if a path matches both). |
65 | | -* `-b, --branch <branch_name>`: Specifies the branch to clone and ingest if the source is a Git URL. Can also be a commit hash. |
| 97 | +### Filtering |
66 | 98 |
|
67 | | -To see all available flags and default values: |
68 | 99 | ```bash |
69 | | -pathdigest --help |
| 100 | +# Exclude additional patterns (adds to built-in defaults) |
| 101 | +pathdigest ./my-project -e "*.test.ts" -e "coverage/" |
| 102 | + |
| 103 | +# Include only specific patterns (overrides excludes) |
| 104 | +pathdigest ./my-project -i "*.go" -i "go.mod" |
| 105 | + |
| 106 | +# Limit max file size (default: 10MB) |
| 107 | +pathdigest ./my-project -s 1048576 # 1MB limit |
70 | 108 | ``` |
71 | 109 |
|
72 | | -### Build Binary |
| 110 | +### Git Integration |
73 | 111 |
|
74 | 112 | ```bash |
75 | | -go build ./cmd/pathdigest |
| 113 | +# Clone and digest a specific branch |
| 114 | +pathdigest https://github.com/user/repo -b develop |
| 115 | + |
| 116 | +# Digest a specific path within a repo |
| 117 | +pathdigest https://github.com/user/repo/tree/main/internal/pkg |
| 118 | +``` |
| 119 | + |
| 120 | +### All Flags |
| 121 | + |
| 122 | +``` |
| 123 | +Flags: |
| 124 | + -b, --branch string Branch to clone and ingest (if source is a Git URL) |
| 125 | + -e, --exclude-pattern strings Glob patterns to exclude (adds to defaults) |
| 126 | + -f, --format string Output format: text or json (default "text") |
| 127 | + -h, --help Help for pathdigest |
| 128 | + -i, --include-pattern strings Glob patterns to include (overrides excludes) |
| 129 | + -s, --max-size int Maximum file size in bytes (default 10485760) |
| 130 | + -o, --output string Output file path (default "pathdigest_digest.txt") |
| 131 | +``` |
| 132 | + |
| 133 | +## Shell Completions |
| 134 | + |
| 135 | +PathDigest supports autocompletion for **bash**, **zsh**, and **fish**. |
| 136 | + |
| 137 | +### Bash |
| 138 | + |
| 139 | +```bash |
| 140 | +# Generate and load completions |
| 141 | +pathdigest completion bash > ~/.config/pathdigest/completion.bash |
| 142 | +echo 'source ~/.config/pathdigest/completion.bash' >> ~/.bashrc |
| 143 | + |
| 144 | +# Or if you use bash-completion (recommended) |
| 145 | +pathdigest completion bash > $(brew --prefix)/etc/bash_completion.d/pathdigest # macOS |
| 146 | +pathdigest completion bash > /etc/bash_completion.d/pathdigest # Linux |
| 147 | +``` |
| 148 | + |
| 149 | +### Zsh |
| 150 | + |
| 151 | +```bash |
| 152 | +# Generate completions to your fpath |
| 153 | +pathdigest completion zsh > "${fpath[1]}/_pathdigest" |
| 154 | + |
| 155 | +# Or manually: |
| 156 | +mkdir -p ~/.zfunc |
| 157 | +pathdigest completion zsh > ~/.zfunc/_pathdigest |
| 158 | + |
| 159 | +# Make sure ~/.zfunc is in your fpath in ~/.zshrc: |
| 160 | +# fpath+=~/.zfunc |
| 161 | +# autoload -U compinit && compinit |
76 | 162 | ``` |
77 | 163 |
|
| 164 | +### Fish |
| 165 | + |
| 166 | +```bash |
| 167 | +pathdigest completion fish > ~/.config/fish/completions/pathdigest.fish |
| 168 | +``` |
| 169 | + |
| 170 | +## Features |
| 171 | + |
| 172 | +- **Versatile Source Input** — Process Git repository URLs (cloning specific branches/commits), local directories, or single files. |
| 173 | +- **Text & JSON Output** — Default text format for human consumption, JSON format (`-f json`) for tools and scripts. |
| 174 | +- **Smart Filtering** — Built-in exclude patterns for common noise (`.git/`, `node_modules/`, `build/`, etc.) plus custom glob patterns. |
| 175 | +- **Git Integration** — Specify branches, commits, and sub-paths when providing a Git URL. |
| 176 | +- **File Size Control** — Set a maximum file size to skip very large files. |
| 177 | +- **Cross-Platform** — Pre-built binaries for macOS, Linux, and Windows (amd64 and arm64). |
| 178 | +- **Shell Completions** — Autocompletion for bash, zsh, and fish. |
| 179 | + |
| 180 | +## Build from Source |
| 181 | + |
| 182 | +```bash |
| 183 | +git clone https://github.com/ga1az/pathdigest.git |
| 184 | +cd pathdigest |
| 185 | +go build ./cmd/pathdigest |
| 186 | +``` |
0 commit comments