一个生成目录树结构的命令行工具
Project description
dir2prompt
一个简单易用的命令行工具,用于生成目录树结构。
功能特点
- 生成清晰的目录树结构
- 支持排除指定目录或文件
- 支持仅包含指定目录或文件
- 跨平台支持(Windows、macOS、Linux)
- 🆕 智能剪切板支持(默认启用)
- 默认同时在终端显示并复制到剪切板
- 本地环境:使用系统剪切板
- SSH环境:通过OSC 52转义序列支持远程剪切板
- 自动检测环境并选择最佳复制方法
- 简洁的命令行界面
安装
使用 pip 安装:
pip install dir2prompt
使用方法
基本用法
# 显示当前目录的树结构(默认同时复制到剪切板)
dir2prompt .
# 显示指定目录的树结构(默认同时复制到剪切板)
dir2prompt /path/to/your/project
高级用法
# 排除特定目录
dir2prompt . --ex node_modules --ex .git
# 仅包含特定目录
dir2prompt /project --in src --in docs
# 组合使用排除和包含
dir2prompt /project --ex __pycache__ --in src --in tests
# 输出到文件(同时复制到剪切板)
dir2prompt . -o tree.txt
# 仅显示在终端,不复制到剪切板
dir2prompt . --no-clipboard
命令行选项
path: 要扫描的目录路径--ex, --exclude: 排除的路径(可多次使用)--in, --include: 包含的路径(可多次使用)-o, --output: 输出到指定文件--no-clipboard: 禁用剪切板功能,仅在终端显示--clipboard-info: 显示剪切板环境信息--clipboard-method: 指定剪切板复制方法 (auto/osc52/pyperclip)-h, --help: 显示帮助信息
剪切板功能详解
默认行为
# 默认同时显示在终端并复制到剪切板
dir2prompt .
# 仅在终端显示,不复制到剪切板
dir2prompt . --no-clipboard
环境自适应
# 本地环境:自动使用系统剪切板
# SSH环境:自动使用OSC 52转义序列
dir2prompt .
# 查看剪切板环境信息
dir2prompt . --clipboard-info
# 强制使用OSC 52方法(适用于SSH)
dir2prompt . --clipboard-method osc52
# 强制使用pyperclip方法(适用于本地)
dir2prompt . --clipboard-method pyperclip
支持的终端
OSC 52转义序列支持以下终端:
- iTerm2, Terminal.app (macOS)
- Windows Terminal, ConEmu (Windows)
- Alacritty, kitty, wezterm (跨平台)
- tmux, screen (终端复用器)
- VS Code集成终端
- 大多数现代终端模拟器
示例输出
project/
├── src/
│ ├── __init__.py
│ └── main.py
├── tests/
│ └── test_main.py
├── pyproject.toml
├── README.md
└── LICENSE
开发
如果你想参与开发或自定义功能:
# 克隆仓库
git clone https://github.com/Jeffjeno/dir2prompt.git
cd dir2prompt
# 安装开发依赖
pip install -e .
# 运行工具
dir2prompt .
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dir2prompts-0.2.1.tar.gz
(10.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dir2prompts-0.2.1.tar.gz.
File metadata
- Download URL: dir2prompts-0.2.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46212701a4e0e3a8e52c5e1d21a9c92cada813ba8c1aec00801498873651f9be
|
|
| MD5 |
726788be9cea119cb2ecf5b5c2c24e2e
|
|
| BLAKE2b-256 |
d81c5f6e8655ac5edb5f4e79ade8c5b81f64cdc8f9fe7bf8c9e7cb49ec32ad79
|
File details
Details for the file dir2prompts-0.2.1-py3-none-any.whl.
File metadata
- Download URL: dir2prompts-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f14593beb2cad731fa974565355c1990e770178dfbf5d202f80b35de8b031a1
|
|
| MD5 |
70d2d448feb0bd239110c163eb9772f2
|
|
| BLAKE2b-256 |
bf7906fab57a149017cc7486bc4f6e971303c5152217ac7d4a2e8d9112add273
|