tree2 1.0.14

A beautiful and feature-rich directory tree visualization tool with colors, emojis, and comprehensive ignore file support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# Tree2

A high-performance directory tree visualization tool written in Rust with colors, emojis, and comprehensive ignore file support. Available as both CLI tool and library crate. **Fully compatible with Linux `tree` command options.**

<p align="center">
  <img src="https://raw.githubusercontent.com/cumulus13/tree2/master/tree2.png" alt="Tree2">
</p>

## 🎦 Demo

<div align="center">
  <a href="https://youtu.be/1BrUiQWi47Y">
    <img src="https://i.ytimg.com/an_webp/1BrUiQWi47Y/mqdefault_6s.webp?du=3000&sqp=CLzY-skG&rs=AOn4CLAfcZjbkZ_1Zw1Yn-fAFJuaUKa88w" alt="How to use mks - tree2 -pt" style="width:100%;">
  </a>
  <br>
  <a href="https://youtu.be/1BrUiQWi47Y">Demo</a>
</div>

## ✨ Features

- 🎨 **Colorful Output**: Beautiful colored output with emojis for better visualization
- 📊 **File Sizes**: Human-readable file sizes with color-coded values
- 🚫 **Multiple Ignore Files**: Automatic support for `.gitignore`, `.dockerignore`, `.pt`, and more
- 🔒 **Default System Exclusions**: `.git`, `.svn`, and other system folders hidden by default
- 🎯 **Exception Patterns**: Wildcard and regex support to override ignore rules
- 📋 **Clipboard Support**: Copy tree output directly to clipboard with `-c` flag
- 🐧 **Linux `tree` Compatible**: Supports all major flags from the Linux `tree` command
-**Blazing Fast**: Optimized Rust implementation for maximum performance
- 🌐 **Cross-Platform**: Works on Windows, macOS, Linux (x86_64, ARM64, ARMv7, i686)
- 📦 **Library & CLI**: Available as both command-line tool and Rust library
- 🦀 **Memory Safe**: Rust's safety guarantees ensure reliability

## 🎨 Color Scheme

- **Folders**: Bright Yellow (#FFFF00) with 📁 emoji
- **Files**: Bright Cyan (#00FFFF) with 📄 emoji
- **Symlinks**: Bright Green (#00FF80) with `->` target path
- **Size Values**: Light magenta (#FF80FF) — White on red background if size is 0
- **Size Units**: Orange (#FFB380)
- **Meta info** (permissions, date, owner): Gray (#A0A0A0)
- **Permission Denied**: White on red background with 🔒 emoji

## 🛠️ Installation

### Using Pre-built Binaries (Recommended)

Download the appropriate binary for your platform from [GitHub Releases](https://github.com/cumulus13/tree2/releases):

#### Linux
```bash
# x86_64 (Standard)
wget https://github.com/cumulus13/tree2/releases/latest/download/tree2-linux-amd64.tar.gz
tar xzf tree2-linux-amd64.tar.gz
sudo mv tree2 /usr/local/bin/

# ARM64 (Raspberry Pi 4+, AWS Graviton)
wget https://github.com/cumulus13/tree2/releases/latest/download/tree2-linux-arm64.tar.gz
tar xzf tree2-linux-arm64.tar.gz
sudo mv tree2 /usr/local/bin/

# ARMv7 (Raspberry Pi 2/3)
wget https://github.com/cumulus13/tree2/releases/latest/download/tree2-linux-armv7.tar.gz
tar xzf tree2-linux-armv7.tar.gz
sudo mv tree2 /usr/local/bin/
```

#### Windows
Download from [releases page](https://github.com/cumulus13/tree2/releases) and extract to a folder in your PATH.

#### macOS
```bash
# Intel Macs
wget https://github.com/cumulus13/tree2/releases/latest/download/tree2-macos-amd64.tar.gz
tar xzf tree2-macos-amd64.tar.gz
sudo mv tree2 /usr/local/bin/

# Apple Silicon (M1/M2/M3)
wget https://github.com/cumulus13/tree2/releases/latest/download/tree2-macos-arm64.tar.gz
tar xzf tree2-macos-arm64.tar.gz
sudo mv tree2 /usr/local/bin/
```

### From crates.io
```bash
cargo install tree2
```

### From Source
```bash
git clone https://github.com/cumulus13/tree2
cd tree2
cargo install --path .
```

## 🌐 Platform Support

Tree2 supports **11 different platforms**:

| OS | Architectures |
|---|---|
| 🐧 Linux | x86_64, ARM64, ARMv7, i686 (+ musl variants) |
| 🪟 Windows | x86_64, ARM64, i686 |
| 🍎 macOS | Intel (x86_64), Apple Silicon (ARM64) |

For detailed platform information, see [PLATFORM_SUPPORT.md](PLATFORM_SUPPORT.md).

## 📖 Usage

### Basic Usage

```bash
# Show current directory tree
tree2

# Show specific directory
tree2 /path/to/directory

# Copy output to clipboard (plain text, no ANSI codes)
tree2 -c

# Show system folders (.git, etc.)
tree2 -a

# Show version info
tree2 -V

# Show help
tree2 --help
```

> **Note:** `-h` is `--human-readable` (Linux `tree` compatibility), not `--help`. Use `--help` for the help screen.

## 📋 Full Options Reference

```
Usage: tree2 [OPTIONS] [PATH]

Arguments:
  [PATH]  Target directory [default: .]
```

### Original tree2 flags

| Flag | Description |
|---|---|
| `-V`, `--version` | Print version information |
| `-e`, `--exclude <NAME>...` | Exclude directories/files by exact name |
| `-c`, `--clipboard` | Copy output to clipboard (plain text) |
| `-i`, `--ignore-file <FILE>...` | Specific ignore file(s) to use |
| `--exception <PATTERN>...` | Exception patterns — matching entries will NOT be excluded (supports wildcards and `regex:` prefix) |
| `-a`, `--all` | Show hidden system folders (`.git`, `.svn`, etc.) |

### Listing & filtering (Linux `tree` compatible)

| Flag | Description |
|---|---|
| `-d`, `--dirs-only` | List directories only |
| `-f`, `--full-path` | Print full path prefix for each entry |
| `-l`, `--follow-links` | Follow symbolic links like directories |
| `-L`, `--level <N>` | Max display depth |
| `-P`, `--pattern <GLOB>` | Only show files matching wildcard pattern (e.g. `"*.rs"`) |
| `-I`, `--ignore-pattern <GLOB>` | Exclude files matching wildcard pattern (e.g. `"*.o"`) |
| `--ignore-case` | Case-insensitive `-P` / `-I` matching |
| `--dirsfirst` | List directories before files |
| `-t`, `--sort-time` | Sort by last modification time (oldest first) |
| `-r`, `--reverse` | Reverse sort order |
| `--filelimit <N>` | Don't descend directories with more than N entries |
| `--prune` | Omit empty directories from output |
| `-x`, `--xdev` | Stay on current filesystem (don't cross mount points) — Unix only |

### File metadata display (Linux `tree` compatible)

| Flag | Description |
|---|---|
| `-p`, `--protections` | Print permissions like `[drwxr-xr-x]` |
| `-u`, `--owner` | Print file owner name / UID — Unix only |
| `-g`, `--group` | Print group name / GID — Unix only |
| `-s`, `--size` | Print size in raw bytes |
| `-h`, `--human-readable` | Human-readable size (already the default; explicit flag for compat) |
| `--si` | Human-readable with SI units (powers of 1000) |
| `-D`, `--date` | Print last modification date/time |
| `-F`, `--classify` | Append type indicators: `/` dirs, `*` executables, `@` symlinks, `\|` FIFOs, `=` sockets |
| `--du` | Report directory size as accumulation of all contained file sizes |
| `--inodes` | Print inode number — Unix only |
| `--device` | Print device number — Unix only |

### Output control (Linux `tree` compatible)

| Flag | Description |
|---|---|
| `--noreport` | Suppress the final `N directories, M files` summary |
| `-o`, `--output <FILE>` | Write output to file (plain text, no ANSI codes) |
| `-n`, `--nocolor` | Disable all ANSI colors |
| `-q`, `--quote-chars` | Replace non-printable characters with `?` |
| `-Q`, `--quote` | Wrap filenames in double quotes |

## 💡 Usage Examples

### Depth & filtering
```bash
# Show only 2 levels deep
tree2 -L 2

# Show only Rust source files
tree2 -P "*.rs"

# Show only directories, 3 levels deep
tree2 -d -L 3

# Exclude all .o files
tree2 -I "*.o"

# Case-insensitive pattern match
tree2 -P "*.RS" --ignore-case
```

### Sorting
```bash
# Directories first
tree2 --dirsfirst

# Sort by modification time, newest last
tree2 -t

# Reverse order
tree2 -r

# Newest first (reverse time sort)
tree2 -t -r
```

### Metadata display
```bash
# Show permissions
tree2 -p

# Show permissions + owner + group
tree2 -p -u -g

# Show modification date
tree2 -D

# Show size in bytes
tree2 -s

# Show size with SI units (1000-based)
tree2 --si

# Show accumulated directory sizes
tree2 --du

# Show inode numbers (Unix only)
tree2 --inodes

# Show all metadata at once
tree2 -p -u -g -D --inodes
```

### Output
```bash
# Save to file (no ANSI codes)
tree2 -o output.txt

# Copy to clipboard
tree2 -c

# No colors
tree2 -n

# Suppress file/dir count summary
tree2 --noreport

# Quote all filenames
tree2 -Q
```

### Combining flags
```bash
# Use only .gitignore, keep all .log files
tree2 -i .gitignore --exception "*.log"

# Show all files matching pattern, dirs first, with dates
tree2 -P "*.toml" --dirsfirst -D

# Complex metadata view with depth limit
tree2 -p -u -D -L 3 --dirsfirst

# Stay on current filesystem only (Unix)
tree2 -x

# Full path + classify indicators
tree2 -f -F
```

### Exception patterns
```bash
# Wildcard: keep all .log files even if in .gitignore
tree2 --exception "*.log"

# Exact match: keep node_modules
tree2 --exception "node_modules"

# Regex pattern: keep test/spec Rust files
tree2 --exception "regex:^(test|spec)_.*\.rs$"

# Multiple exceptions
tree2 --exception "*.log" "*.md" "important_*"
```

## 📄 Creating a .pt File

The `.pt` file works like `.gitignore` but is specific to tree2:

```bash
cat > .pt << EOF
# Custom ignores for tree2
*.tmp
*.cache
local_settings.json
dev_notes/
EOF

# tree2 will automatically use it
tree2
```

## 📋 Output Example

```
📂 /home/user/project/
├── 📁 src/
│   ├── 📄 main.rs (12.45 KB)
│   └── 📄 lib.rs (2.34 KB)
├── 📁 tests/
│   └── 📄 integration_test.rs (2.10 KB)
├── 📄 Cargo.toml (1.20 KB)
├── 📄 README.md (4.50 KB)
└── 🔒 [Permission Denied]

2 directories, 4 files
```

### With metadata flags (`-p -u -D`)
```
📂 /home/user/project/
├── [-rwxr-xr-x] alice [2025-11-22 14:30] 📁 src/
│   └── [-rw-r--r--] alice [2025-11-20 09:15] 📄 main.rs (12.45 KB)
└── [-rw-r--r--] alice [2025-11-21 11:00] 📄 Cargo.toml (1.20 KB)

1 directory, 2 files
```

### Clipboard Output

When using `-c`, the output copied to clipboard is **plain text without ANSI color codes**, making it perfect for pasting into documentation, emails, Markdown files, or code reviews.

## 🚀 Performance

- Zero-cost abstractions
- Minimal memory allocations
- Efficient directory traversal
- Fast pattern matching with HashSet
- Optimized wildcard matching algorithm

## 📚 Library Usage

Add to your `Cargo.toml`:

```toml
[dependencies]
tree2 = "2.0"
```

### Basic Example

```rust
use tree2::TreeBuilder;

fn main() {
    let tree = TreeBuilder::new()
        .path(".")
        .excludes(vec!["target", ".git"])
        .build();

    tree.print();
}
```

### Advanced Example

```rust
use tree2::{TreeBuilder, TreeConfig};

fn main() {
    let config = TreeConfig {
        path: ".".into(),
        excludes: vec!["target".into(), ".git".into()],
        ignore_files: vec![".gitignore".into(), ".dockerignore".into()],
        exceptions: vec!["*.log".into()],
        show_all: 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

```toml
[dependencies]
clap = { version = "4.0", features = ["derive"] }
dunce = "1.0.4"
cli-clipboard = "0.4"
clap-version-flag = "1.0.5"
regex = "1.10"
```

## 🏗️ Building from Source

### Prerequisites
- Rust 1.70 or higher
- Cargo

### Build Steps
```bash
git clone https://github.com/cumulus13/tree2
cd tree2

# Debug build
cargo build

# Release build
cargo build --release

# Run tests
cargo test

# Run clippy
cargo clippy -- -D warnings

# Check formatting
cargo fmt --all -- --check
```

### Cross-Compilation

```bash
# Install target
rustup target add aarch64-unknown-linux-gnu

# Build
cargo build --release --target aarch64-unknown-linux-gnu

# Or use cross for easier cross-compilation
cargo install cross
cross build --release --target aarch64-unknown-linux-gnu
```

## 🤝 Contributing

We welcome contributions!

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. 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]https://github.com/cumulus13

[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)

[![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)

[Support me on Patreon](https://www.patreon.com/cumulus13)

## 💬 Support

If you encounter any issues or have questions:

1. Check the [Issues]https://github.com/cumulus13/tree2/issues page
2. Create a new issue with detailed description
3. Read the [Documentation]PLATFORM_SUPPORT.md
4. Contact: cumulus13@gmail.com

## 📝 Changelog

### v1.0.14 (Latest)
- **Added**: Full Linux `tree` command compatibility
-**Added**: `-L/--level` max depth flag
-**Added**: `-d/--dirs-only` directories-only listing
-**Added**: `-f/--full-path` full path prefix display
-**Added**: `-P/--pattern` and `-I/--ignore-pattern` wildcard filtering
-**Added**: `--ignore-case` for case-insensitive pattern matching
-**Added**: `--dirsfirst` sort order
-**Added**: `-t/--sort-time` and `-r/--reverse` sort flags
-**Added**: `-p/--protections` permissions display (Unix)
-**Added**: `-u/--owner` and `-g/--group` metadata (Unix)
-**Added**: `-s/--size` raw bytes, `-h/--human-readable`, `--si` size flags
-**Added**: `-D/--date` modification date display
-**Added**: `-F/--classify` type indicator suffixes
-**Added**: `--filelimit` directory entry limit
-**Added**: `--prune` empty directory pruning
-**Added**: `--du` accumulated directory sizes
-**Added**: `--noreport` suppress summary line
-**Added**: `-o/--output` write to file
-**Added**: `-n/--nocolor` disable ANSI colors
-**Added**: `-q/--quote-chars` and `-Q/--quote` filename quoting
-**Added**: `-x/--xdev` stay on current filesystem (Unix)
-**Added**: `--inodes` and `--device` inode/device display (Unix)
-**Added**: Summary line `N directories, M files` at end of output
-**Added**: Symlink display with `->` target in bright green
-**Added**: Meta-info prefix colored in gray
- 🐛 **Fixed**: Cross-platform build — all Unix-specific APIs gated with `#[cfg(unix)]`
- 🐛 **Fixed**: All clippy warnings (`is_multiple_of`, `sort_by_key`, argument count)
- ⚠️ **Breaking**: `-h` is now `--human-readable` (Linux tree compat). Use `--help` for help.

### v1.0.13
- 🐛 **Fixed**: Wildcard pattern matching in ignore files (`.gitignore`, `.pt`, etc.)
- 🐛 **Fixed**: Tree connector logic for correct display
-**Added**: Default system folder exclusion (`.git`, `.svn`, etc.)
-**Added**: `-a/--all` flag to show hidden system folders
- 📚 **Improved**: Documentation and troubleshooting guides

### v1.0.10
- **Added**: Multiple ignore file support (`.gitignore`, `.dockerignore`, `.pt`, etc.)
-**Added**: Exception patterns with wildcard, regex, and exact match
-**Added**: Selective ignore file usage with `-i` flag
-**Added**: Custom `.pt` ignore file support
- 🚀 **Improved**: Pattern matching algorithm
- 📚 **Added**: Comprehensive documentation (QUICKSTART, EXAMPLES, TROUBLESHOOTING)

### v1.0.9
- ✅ Fixed exact match exclusion (`.git` no longer excludes `.github`)
- ✨ Added clipboard support with `-c` flag
- 📝 Improved version info with `-V` flag
- 🎨 Better color scheme with true color support
- ⚡ Performance optimizations

## 🔗 Links

- [QUICKSTART Guide]QUICKSTART.md - Get started in 5 minutes
- [Examples]EXAMPLES.md - 48+ practical usage examples
- [Platform Support]PLATFORM_SUPPORT.md - Detailed platform information
- [Changelog]CHANGELOG.md - Full version history

---

**Enjoy blazing-fast directory visualization with Tree2!** 🚀🦀