Skip to content

Commit d909845

Browse files
committed
docs: update README with usage, JSON output, shell completions
- Fix shell completion generation (PersistentPreRunE was breaking subcommands like 'completion' and 'version') - Add comprehensive usage examples for text and JSON output - Document installation methods (go install, install.sh, releases) - Add shell completion instructions for bash, zsh, and fish - Update feature list with JSON output and cross-platform binaries
1 parent 34bc9de commit d909845

2 files changed

Lines changed: 153 additions & 35 deletions

File tree

README.md

Lines changed: 143 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,186 @@
11
# PathDigest
22

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.
44

55
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.
66

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.
88
99
## Installation
1010

11-
### Via `go install` (Recommended if you have Go installed)
11+
### Via `go install` (requires Go 1.23+)
1212

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`.
1414

1515
```bash
1616
go install github.com/ga1az/pathdigest@latest
1717
```
1818

19-
### Via `install.sh` (Recommended if you don't have Go installed)
19+
### Via install script (macOS & Linux)
2020

2121
```bash
22+
# Install to default directory ($GOPATH/bin or ./bin)
2223
curl -sSfL https://raw.githubusercontent.com/ga1az/pathdigest/main/install.sh | sh -s
2324

2425
# Install to a specific directory
2526
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/
2656
```
2757

2858
## Usage
2959

60+
### Basic
61+
3062
```bash
31-
pathdigest <source>
63+
# Digest a local directory (outputs to pathdigest_digest.txt by default)
64+
pathdigest ./my-project
3265

33-
//Git URL
66+
# Digest a Git repository URL
3467
pathdigest https://github.com/ga1az/pathdigest
3568

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
3874
```
3975

40-
## Features
76+
### JSON Output
4177

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
5583

84+
# JSON to stdout
85+
pathdigest ./my-project -f json -o -
5686

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+
```
5890

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
6096

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
6698

67-
To see all available flags and default values:
6899
```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
70108
```
71109

72-
### Build Binary
110+
### Git Integration
73111

74112
```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
76162
```
77163

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+
```

cmd/root.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ You can specify a local path or a repository URL as the source.`,
4141
Args: cobra.ExactArgs(1),
4242
Version: appVersion,
4343
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
44+
// Only parse exclude patterns when running the root command
45+
if !cmd.Flags().Changed("exclude-pattern") && !cmd.HasFlags() {
46+
return nil
47+
}
48+
if !cmd.Flags().HasAvailableFlags() {
49+
return nil
50+
}
51+
4452
userExcludePatterns, err := cmd.Flags().GetStringSlice("exclude-pattern")
4553
if err != nil {
46-
return fmt.Errorf("error parsing exclude patterns: %w", err)
54+
// Flag doesn't exist for this subcommand (e.g. completion, version) — skip
55+
return nil
4756
}
4857

4958
finalExcludesSet := make(map[string]struct{})

0 commit comments

Comments
 (0)