Files
cliprepo/README.zh-CN.md
T

92 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# cliprepo
`cliprepo` 是一个用 Go 语言编写的轻量、高效的命令行工具(CLI)。它可以将你代码库的目录结构和指定的文件内容一键打包成格式化的 Markdown 文本,专门用于快速为大语言模型(如 GPT、Claude、DeepSeek)构建完整的上下文。
## 功能特性
- **目录树生成**:自动生成清晰的 ASCII 目录树,并且会自动遵循 `.gitignore` 的过滤规则。
- **灵活的文件过滤**:支持通过预设组合(Preset)匹配文件(如 `*``cmd/*` 或具体文件路径)。
- **智能 Gitignore 过滤**:自动跳过 `.gitignore` 中指定的文件和文件夹(例如 `.git``node_modules``.DS_Store`)。
- **剪贴板集成**:一键将生成的 Prompt 复制到系统剪贴板,省去手动复制或保存文件的烦恼。
- **自定义模板**:支持通过 YAML 配置文件自定义代码块向 LLM 展示的模板。
## 安装指南
请确保你已经安装了 [Go](https://go.dev/)(版本 1.26 或更高),然后克隆本仓库并执行:
```bash
chmod +x install.sh
./install.sh
```
这将会把编译好的 `cliprepo` 二进制文件安装到你的 `$GOPATH/bin` 目录下。
## 配置文件
在项目根目录下创建一个 `.cliprepo.yaml` 文件,用于管理路径模式、自定义提示词模板和文件组预设:
```yaml
config:
path_mode: relative # 可选值: 'relative' (相对路径) 或 'absolute' (绝对路径)
prompts:
preset: "下面的代码来自文件 {{path}}\n---\n{{content}}"
preset:
all:
- "*" # 扫描并包含库中所有未被 ignore 的文件
internal:
- "internal/tree/*"
- "internal/resolver/resolver.go"
cmd:
- "cmd/*"
```
## 使用方法
通过 `run` 命令并指定 `.cliprepo.yaml` 中配置的预设(preset)键名来运行该工具。
### 输出到终端屏幕
```bash
cliprepo run --delineate cmd
```
### 直接复制到剪贴板
```bash
cliprepo run --delineate all --clipboard
```
### 命令行参数(Flags
* `--delineate` (string): 指定要使用的 `.cliprepo.yaml` 中的预设键名(必填)。
* `--clipboard` (bool): 将生成的结果直接复制到系统剪贴板,不再在终端打印。
## 输出示例
当你运行 `cliprepo run --delineate cmd` 时,输出的内容格式如下:
```text
.
├── cmd
│ ├── root.go
│ └── run.go
└── main.go
下面的代码来自文件 cmd/root.go
---
package cmd
...
下面的代码来自文件 cmd/run.go
---
package cmd
...
```
## 开源协议
[MIT License](https://www.google.com/search?q=LICENSE)