Tree2
A high-performance directory tree visualization tool written in Rust with colors, emojis, and gitignore support. Available as both CLI tool and library crate.
🎦 Demo
Features
- 🎨 Colorful Output: Beautiful colored output with emojis for better visualization
- 📊 File Sizes: Human-readable file sizes with color-coded values
- 🔒 Permission Handling: Gracefully handles permission denied errors
- 📋 Exclusion Support: Supports
.gitignorefiles and custom exclude patterns (exact match only) - 📋 Clipboard Support: Copy tree output directly to clipboard with
-cflag - ⚡ Blazing Fast: Optimized Rust implementation for maximum performance
- 📦 Library & CLI: Available as both command-line tool and Rust library
- 🦀 Memory Safe: Rust's safety guarantees ensure reliability
- 💻 Cross-Platform: Works on Windows, macOS, and Linux
Color Scheme
- Folders: Bright Yellow (#FFFF00) with 📁 emoji
- Files: Bright Cyan (#00FFFF) with 📄 emoji
- Size Values: Light magenta (#FF80FF) - White on red background if size is 0
- Size Units: Orange (#FFB380)
- Permission Denied: White on red background with 🔒 emoji
Installation
Method 1: Install from crates.io
Method 2: Install from source
Method 3: Build and run directly
Usage
Basic Usage
# Show current directory tree
# Show specific directory
# Copy output to clipboard
# Show version info
Command Line Options
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
Options Details
| 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 |
Important: Exact Match Exclusion
The -e flag uses exact match only. This means:
-e .gitwill exclude only.gitfolder-e .gitwill NOT exclude.githubfolder- Each exclusion must match the exact name
With Exclusions
# Exclude single pattern
# Exclude multiple patterns (space-separated)
# Exclude multiple patterns (multiple -e flags)
# With clipboard
Examples
# Typical Rust project directory
# Python project
# Node.js project
# With clipboard for sharing
# Specific path with exclusions
Usage: tree2 [OPTIONS] [PATH]
Arguments: [PATH] [default: .]
Options: -e, --exclude [...] Exclude directories/files (exact match only) -c, --clipboard Copy result to clipboard -V, --version Print version information -h, --help Print help
## 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"
Basic Example
use TreeBuilder;
Advanced Example
use ;
Dependencies
[]
= { = "4.5", = ["derive"] }
= "1.0"
= "0.4"
= "1.0.5"
Building from Source
Prerequisites
- Rust 1.60 or higher
- Cargo
Build Steps
# Debug build
# Release build
# Run tests
# Run with arguments
Performance
The Rust version is optimized for performance:
- Zero-cost abstractions
- Minimal memory allocations
- Efficient directory traversal
- Fast pattern matching with HashSet
- Optimized sorting algorithms
Key Improvements in Latest Version
🔧 Fixed: Exact Match Exclusion
Previously, -e .git would also exclude .github and .gitignore. Now it uses exact match only:
// Old (incorrect): .git excludes .github too
entry.starts_with // ❌
// New (correct): exact match only
excludes.contains // ✅
📋 New: Clipboard Support
Copy tree output with -c flag:
- Automatic ANSI color stripping
- Plain text output for universal compatibility
- Success/error feedback messages
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Hadi Cahyadi
- Email: cumulus13@gmail.com
- GitHub: cumulus13
Support
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed description
- Contact: cumulus13@gmail.com
- Documentation: docs.rs/tree2
Changelog
v1.0.9
- ✅ Fixed exact match exclusion (
.gitno longer excludes.github) - ✨ Added clipboard support with
-cflag - 📝 Improved version info with
-Vflag - 🎨 Better color scheme with true color support
- ⚡ Performance optimizations
Enjoy blazing-fast directory visualization with Tree2 Rust! 🚀🦀
