| Crates.io | tree2 |
| lib.rs | tree2 |
| version | 1.0.9 |
| created_at | 2025-11-22 07:07:39.405394+00 |
| updated_at | 2025-12-15 08:58:36.235772+00 |
| description | A beautiful and feature-rich directory tree visualization tool with colors and emojis |
| homepage | https://github.com/cumulus13/tree2 |
| repository | https://github.com/cumulus13/tree2 |
| max_upload_size | |
| id | 1944985 |
| size | 67,630 |
A high-performance directory tree visualization tool written in Rust with colors, emojis, and gitignore support. Available as both CLI tool and library crate.
.gitignore files and custom exclude patterns (exact match only)-c flagcargo install tree2
git clone https://github.com/cumulus13/tree2
cd tree2
cargo install --path .
git clone https://github.com/cumulus13/tree2
cd tree2
cargo run --release -- [options]
# Show current directory tree
tree2
# Show specific directory
tree2 /path/to/directory
# Copy output to clipboard
tree2 -c
# Show version info
tree2 -V
Usage: tree2 [OPTIONS] [PATH]
Arguments:
[PATH] Target directory [default: .]
Options:
-e, --exclude <EXCLUDE>... Exclude directories/files (exact match only)
-c, --clipboard Copy result to clipboard
-V, --version Print version information
-h, --help Print help
| Flag | Long Form | Description |
|---|---|---|
-e |
--exclude |
Exclude specific directories/files (exact match only, multiple values supported) |
-c |
--clipboard |
Copy tree output to clipboard (without ANSI colors) |
-V |
--version |
Show version, author, and repository information |
-h |
--help |
Display help message |
The -e flag uses exact match only. This means:
-e .git will exclude only .git folder-e .git will NOT exclude .github folder# Exclude single pattern
tree2 -e target
# Exclude multiple patterns (space-separated)
tree2 -e target .git node_modules
# Exclude multiple patterns (multiple -e flags)
tree2 -e target -e .git -e node_modules
# With clipboard
tree2 -e target -e .git -c
# Typical Rust project directory
tree2 -e target -e .git
# Python project
tree2 -e __pycache__ -e .venv -e dist
# Node.js project
tree2 -e node_modules -e dist -e .next
# With clipboard for sharing
tree2 -e target -e node_modules -c
# Specific path with exclusions
tree2 /path/to/project -e target -e .git
Usage: tree2 [OPTIONS] [PATH]
Arguments: [PATH] [default: .]
Options:
-e, --exclude [
## Output Example
📂 /home/user/project/ ├── 📁 src/ │ ├── 📄 main.rs (12.45 KB) │ └── 📄 lib.rs (0.00 B) ├── 📁 tests/ │ └── 📄 integration_test.rs (2.10 KB) ├── 📄 Cargo.toml (1.20 KB) ├── 📄 README.md (4.50 KB) └── 🔒 [Permission Denied]
### Clipboard Output
When using `-c` flag, the output copied to clipboard is **plain text without ANSI color codes**, making it perfect for:
- Pasting into documentation
- Sharing in emails or chat
- Including in Markdown files
- Code reviews and discussions
## Library Usage
Add to your `Cargo.toml`:
```toml
[dependencies]
tree2 = "0.1.0"
use tree2::TreeBuilder;
fn main() {
let tree = TreeBuilder::new()
.path(".")
.excludes(vec!["target", ".git"])
.build();
tree.print();
}
use tree2::{TreeBuilder, TreeConfig};
fn main() {
let config = TreeConfig {
path: ".".into(),
excludes: vec!["target".into(), ".git".into(), "node_modules".into()],
show_hidden: false,
max_depth: Some(5),
};
let tree = TreeBuilder::from_config(config).build();
tree.print();
// Or get the output as string
let output = tree.to_string();
println!("{}", output);
}
[dependencies]
clap = { version = "4.5", features = ["derive"] }
dunce = "1.0"
cli-clipboard = "0.4"
clap-version-flag = "1.0.5"
git clone https://github.com/cumulus13/tree2
cd tree2
# Debug build
cargo build
# Release build
cargo build --release
# Run tests
cargo test
# Run with arguments
cargo run --release -- -e target -c
The Rust version is optimized for performance:
Previously, -e .git would also exclude .github and .gitignore. Now it uses exact match only:
// Old (incorrect): .git excludes .github too
entry.starts_with(ex) // ❌
// New (correct): exact match only
excludes.contains(entry) // ✅
Copy tree output with -c flag:
Automatic ANSI color stripping
Plain text output for universal compatibility
Success/error feedback messages
We welcome contributions! Please see our Contributing Guide for details.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Hadi Cahyadi
If you encounter any issues or have questions:
.git no longer excludes .github)-c flag-V flagEnjoy blazing-fast directory visualization with Tree2 Rust! 🚀🦀