rust-filesearch 0.1.0

Fast developer tools: fexplorer (file explorer) and px (project switcher with fuzzy search and frecency)
Documentation
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# 🦀 rust_filesearch - Fast Developer Tools

A dual-binary Rust workspace providing two powerful command-line tools for developers:

- **fexplorer** - Fast file system exploration, searching, and analysis
- **px** - Intelligent project switcher with fuzzy search and frecency ranking

[![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg)](https://www.rust-lang.org)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)

---

## 🎯 Quick Start

```bash
# Install both tools
cargo install --path . --bin fexplorer
cargo install --path . --bin px

# Set up px
px init
# Edit ~/.config/px/config.toml with your project directories
px sync

# Now you're ready!
px open myproject           # Jump to a project instantly
fx find . --name "*.rs"     # Find files in current project
```

---

## 📦 Two Tools, One Workspace

### fexplorer - File System Explorer
Fast filesystem traversal, searching, and analysis tool.

**Use fexplorer when:**
- Finding specific files across projects
- Analyzing disk usage
- Generating reports (HTML/Markdown)
- Exploring unfamiliar codebases
- Need structured output (JSON/CSV)

### px - Project Switcher
Intelligent project management with fuzzy search and frecency ranking.

**Use px when:**
- Switching between projects quickly
- Opening projects in editor + terminal
- Tracking project access patterns
- Finding projects by name/fuzzy match
- Managing multiple development workspaces

**See [WORKFLOWS.md](docs/WORKFLOWS.md) for powerful ways to combine both tools!**

---

## ✨ fexplorer Features

- 🚀 **Fast traversal** with parallel processing (default)
- 🔍 **Powerful filtering** by name (glob/regex), extension, size, date, and type
- 📊 **Multiple output formats**: pretty (colored), JSON, NDJSON, CSV
- 📄 **Template export**: HTML and Markdown reports (default)
- 🌳 **Tree view** with ASCII art visualization
- 📏 **Size analysis** with directory aggregation (du-like)
- 🔎 **Content search** (grep functionality, default)
- 🔁 **Duplicate detection** via BLAKE3 hashing (optional)
- 🔗 **Git integration** for status and change tracking (optional)
- 👁️ **Watch mode** for real-time filesystem monitoring (optional)
- 🙈 **Respects .gitignore** by default
- ⚙️ **Cross-platform**: macOS, Linux, Windows
- 🎨 **TTY-aware** colored output
- 🔒 **Memory-safe** Rust implementation with zero unsafe code

## 📦 Installation

### Quick Install (Recommended)

```bash
cd rust_filesearch
cargo install --path .
```

This installs `fexplorer` to `~/.cargo/bin/` with default features:
- ✅ Parallel traversal (fast)
- ✅ Template export (HTML/Markdown)
- ✅ Content search (grep)

### Using the Install Script

```bash
./install.sh
```

### Verify Installation

```bash
which fexplorer
# Should show: /Users/yourusername/.cargo/bin/fexplorer

fexplorer --version
# Should show: fexplorer 0.1.0
```

### macOS Setup

If `fexplorer` command isn't found, add cargo bin to your PATH:

```bash
# Add to ~/.zshrc
export PATH="$HOME/.cargo/bin:$PATH"

# Reload shell
source ~/.zshrc
```

### Optional Features

```bash
# Install with all features
cargo install --path . --all-features

# Install with specific features
cargo install --path . --features "dedup,git,tui"
```

**Available features:**
- `parallel` (default) - Multi-threaded traversal
- `templates` (default) - HTML/Markdown export
- `grep` (default) - Content search
- `watch` - Filesystem monitoring
- `progress` - Progress bars
- `dedup` - Duplicate file detection
- `git` - Git integration
- `tui` - Interactive TUI mode
- `trends` - Filesystem trend analysis

---

## ✨ px Features

- 🚀 **Fast project switching** - Open projects in editor + iTerm2 instantly
- 🔍 **Fuzzy search** - Find projects by partial name matching
- 📊 **Frecency ranking** - Most frequent and recent projects surface first
- 📁 **Git integration** - Track branches, commits, and uncommitted changes
- 🎯 **Smart filtering** - Filter by uncommitted changes, inactive projects
- 💾 **Caching** - Fast startup with JSON index caching
- 📝 **Rich info** - View project details, git status, README excerpts
- 🔄 **Auto-sync** - Keep project index up to date
- ⚙️ **Configurable** - Set editor, scan directories, and more

## 📦 px Installation

```bash
# Install px binary
cargo install --path . --bin px

# Initialize configuration
px init

# Edit config with your project directories
nano ~/.config/px/config.toml

# Example config:
# scan_dirs = [
#   "/Users/you/Developer/projects",
#   "/Users/you/Work/repos"
# ]
# default_editor = "cursor"  # or "code", "vim", etc.

# Sync and index all projects
px sync
```

**Verify:**
```bash
px list                     # List all projects
px info myproject          # Show project details
px open myproject          # Open in editor + terminal
```

**Shell Aliases (recommended):**
```bash
# Add to ~/.zshrc
alias p='px open'
alias pl='px list'
alias pi='px info'
alias ps='px sync'
```

---

## 🚀 fexplorer Usage

### List Files

List entries with metadata and sorting:

```bash
# List current directory
fexplorer list

# List with custom sorting
fexplorer list --sort size --desc

# Show directories first
fexplorer list --dirs-first --sort name

# Include hidden files
fexplorer list --hidden

# Output as JSON
fexplorer list --format json

# Custom columns
fexplorer list --columns name,size,mtime
```

### Tree View

Display directory structure as an ASCII tree:

```bash
# Show directory tree
fexplorer tree .

# Limit depth
fexplorer tree ~/projects --max-depth 3

# Directories first
fexplorer tree --dirs-first

# Disable .gitignore filtering
fexplorer tree --no-gitignore
```

### Find Files

Search with powerful filtering:

```bash
# Find Rust files (use --name, not --names!)
fexplorer find . --name "*.rs"

# Multiple patterns
fexplorer find . --name "*.rs" --name "*.toml"

# By extension
fexplorer find . --ext rs,toml,md

# Regex pattern
fexplorer find . --regex "^test_.*\.rs$"

# Size range
fexplorer find . --min-size 10KB --max-size 10MB

# Modified after date
fexplorer find . --after "2024-01-01"
fexplorer find . --after "1 day ago"

# Combine filters
fexplorer find . --name "*.rs" --min-size 1KB --after "7 days ago"

# Find only directories
fexplorer find . --kind dir

# Category-based search
fexplorer find . --category source
```

### Template Export (NEW!)

Generate HTML or Markdown reports:

```bash
# HTML report of recent changes
fexplorer find . --after "1 day ago" --template html > report.html

# Markdown table
fexplorer find . --name "*.md" --template markdown > files.md

# Open in browser (macOS)
fexplorer find . --after "1 day ago" --template html > report.html && open report.html
```

### Suppress macOS Permission Warnings

When scanning from home directory:

```bash
# Use -q (quiet) flag
fexplorer -q find ~ --name "*.pdf"

# Or search specific directories
fexplorer find ~/Developer --name "*.rs"
fexplorer find ~/Documents --name "*.md"
```

---

## 🚀 px Usage

### Quick Commands

```bash
# List all projects (sorted by frecency)
px list

# Filter projects
px list --filter has-changes      # Show projects with uncommitted changes
px list --filter inactive-30d     # Projects not accessed in 30 days
px list --filter inactive-90d     # Projects not accessed in 90 days

# Open project (fuzzy match)
px open myproj                    # Matches "myproject"
px open whatsgood                 # Opens "whatsgood-homepage"

# Show project details
px info myproject

# Sync/rebuild index
px sync

# Initialize config
px init
```

### Real-World Examples

```bash
# Morning routine: check what needs attention
px list --filter has-changes

# Jump to project instantly
px open rust_filesearch
# Opens in Cursor + creates iTerm2 window at project directory

# Find project you haven't touched in a while
px list --filter inactive-90d

# Get detailed info before starting work
px info whatsgood-homepage
# Shows:
#   - Branch and git status
#   - Last commit details
#   - README excerpt
#   - Access frequency stats

# After cloning new repos
px sync
# Scans configured directories and updates index
```

### Combined with fexplorer

```bash
# Open project, then explore files
px open myproject
fx find . --name "*.rs" --after "7 days ago"

# Find files across all projects
fx find ~/Developer --name "config.toml"

# Find large uncommitted files
px list --filter has-changes | while read proj; do
  fx git $(px info $proj | grep Path: | awk '{print $2}') --status modified
done
```

**See [docs/PX_USER_GUIDE.md](docs/PX_USER_GUIDE.md) and [docs/WORKFLOWS.md](docs/WORKFLOWS.md) for advanced usage!**

---

## 🚀 fexplorer Size Analysis

Calculate and display file/directory sizes:

```bash
# Show sizes
fexplorer size .

# Aggregate directory sizes (like 'du')
fexplorer size . --aggregate --du

# Top 20 largest files
fexplorer size . --top 20

# Sort by size descending (default for size command)
fexplorer size ~/Downloads --format json
```

### Watch Mode

Monitor filesystem changes in real-time (requires `watch` feature):

```bash
# Watch for all changes
fexplorer watch ~/Downloads

# Watch specific events
fexplorer watch . --events create,modify

# Output as NDJSON (streaming)
fexplorer watch . --format ndjson
```

## 🎛️ Options

### Global Options

- `--no-color` - Disable colored output
- `-q, --quiet` - Quiet mode (suppress non-essential output)

### Common Options (All Subcommands)

- `--max-depth <N>` - Maximum traversal depth
- `--hidden` - Include hidden files
- `--no-gitignore` - Disable .gitignore filtering
- `--follow-symlinks` - Follow symbolic links
- `--format <FORMAT>` - Output format: `pretty`, `json`, `ndjson`, `csv`
- `--columns <COLS>` - Comma-separated columns: `path,name,size,mtime,kind,perms,owner`

### Parallel Feature Options

With `--features parallel`:

- `--threads <N>` - Number of threads for parallel traversal (default: 4)

### Progress Feature Options

With `--features progress`:

- `--progress` - Show progress bar during traversal

## 📊 Output Formats

### Pretty (Default)

Human-readable colored output with automatic column sizing:

```
file1.txt  1.2 KiB  2024-01-15 10:30:00  file
dir1/      0 B      2024-01-15 10:25:00  dir
```

### JSON

Structured JSON array (buffered):

```json
[
  {
    "path": "file1.txt",
    "name": "file1.txt",
    "size": 1234,
    "kind": "file",
    "mtime": "2024-01-15T10:30:00Z"
  }
]
```

### NDJSON

Streaming newline-delimited JSON (one object per line):

```json
{"path":"file1.txt","name":"file1.txt","size":1234,"kind":"file","mtime":"2024-01-15T10:30:00Z"}
{"path":"file2.txt","name":"file2.txt","size":5678,"kind":"file","mtime":"2024-01-15T10:31:00Z"}
```

### CSV

Comma-separated values with header:

```csv
path,name,size,mtime,kind
file1.txt,file1.txt,1234,2024-01-15T10:30:00Z,file
file2.txt,file2.txt,5678,2024-01-15T10:31:00Z,file
```

## 🔧 Development

### Prerequisites

- Rust 1.70+ (stable)
- Cargo

### Building

```bash
# Debug build
cargo build

# Release build (optimized)
cargo build --release

# With all features
cargo build --release --all-features
```

### Testing

```bash
# Run all tests
cargo test

# Run unit tests only
cargo test --lib

# Run integration tests
cargo test --test integration_tests

# With all features
cargo test --all-features
```

### Linting and Formatting

```bash
# Format code
cargo fmt

# Lint with clippy
cargo clippy --all-targets --all-features -- -D warnings

# Check without building
cargo check
```

### Using Justfile

A `justfile` is provided for common tasks:

```bash
# Show available commands
just

# Format, lint, and test
just check

# Build release
just build

# Run example
just run list .
```

## 🏗️ Architecture

This is a **dual-binary Cargo workspace** with ~80% code reuse:

```
rust_filesearch/
├── src/
│   ├── bin/
│   │   ├── fexplorer.rs  # fexplorer CLI entry point
│   │   └── px.rs         # px CLI entry point
│   ├── lib.rs            # Shared library interface
│   ├── cli.rs            # Shared argument parsing (clap)
│   ├── errors.rs         # Shared error types (thiserror)
│   ├── models.rs         # Shared data structures
│   ├── config.rs         # Shared config (fexplorer + px)
│   ├── util.rs           # Shared utilities
│   ├── fs/
│   │   ├── traverse.rs   # Directory traversal (used by both)
│   │   ├── filters.rs    # Predicate-based filtering
│   │   ├── metadata.rs   # Cross-platform metadata
│   │   ├── size.rs       # Directory size calculation
│   │   ├── git.rs        # Git operations (used by both)
│   │   └── watch.rs      # Filesystem watching (feature-gated)
│   ├── output/
│   │   ├── format.rs     # OutputSink trait
│   │   ├── pretty.rs     # Colored terminal output
│   │   ├── json.rs       # JSON & NDJSON formatters
│   │   └── csvw.rs       # CSV formatter
│   └── px/
│       ├── commands.rs   # px command implementations
│       ├── project.rs    # Project model with git status
│       ├── index.rs      # Project index with JSON caching
│       ├── search.rs     # Fuzzy search with SkimMatcherV2
│       └── frecency.rs   # Firefox-style frecency algorithm
├── tests/
│   └── integration_tests.rs  # E2E tests with assert_cmd
└── Cargo.toml            # Workspace with [[bin]] entries
```

**Key Design Decisions:**
- **Dual binary approach**: Separate binaries sharing 80%+ infrastructure
- **Git integration reuse**: Both tools use same git operations from `fs/git.rs`
- **Config separation**: `PxConfig` for px, existing config for fexplorer
- **JSON caching**: px uses `~/.cache/px/projects.json` for fast startup
- **Frecency algorithm**: Firefox-style ranking (frequency + recency)

## 📈 Performance

### fexplorer Performance
- **Streaming architecture**: Processes entries as they're discovered, minimizing memory usage
- **Parallel traversal** (optional): Leverages rayon and jwalk for multi-threaded directory walking
- **Zero-copy where possible**: Uses references and borrows to avoid unnecessary clones
- **Respects .gitignore**: Skips ignored paths early, reducing I/O

**Benchmarks** (tested on ~50,000 files):

| Command | Time (Cold Cache) | Time (Warm Cache) |
|---------|-------------------|-------------------|
| `find .` (GNU find) | 850ms | 120ms |
| `fexplorer list .` | 780ms | 110ms |
| `fexplorer list . --features parallel` | 420ms | 65ms |

### px Performance
- **JSON caching**: Fast startup (~10ms) after initial sync
- **Parallel scanning**: Uses rayon + jwalk for multi-threaded project discovery
- **Respects gitignore**: Skips ignored directories during sync
- **Fuzzy matching**: SkimMatcherV2 provides fast substring matching

**Real-World Results:**

| Operation | Projects | Time |
|-----------|----------|------|
| `px sync` (4 scan dirs) | 243 | 12.02s |
| `px list` (cached) | 243 | 10ms |
| `px open <query>` | 243 | 15ms |
| `px info <query>` | 243 | 12ms |

**Memory usage:** ~5MB for index with 243 projects

## 🛣️ Roadmap

### Completed ✅
- [x] Parallel traversal
- [x] Template export (HTML/Markdown)
- [x] Content search (grep)
- [x] Duplicate file detection
- [x] Git integration
- [x] Config profiles
- [x] **px - Project switcher with frecency**
### In Progress 🚧
- [ ] TUI mode with interactive navigation
- [ ] Enhanced px features (Obsidian vault integration)

### Planned 📋
- [ ] Archive support (zip, tar.gz)
- [ ] Configurable ignore patterns beyond .gitignore
- [ ] Export directory structure as JSON schema
- [ ] Plugin system for custom filters
- [ ] Publish to crates.io

## 📚 Documentation

### Core Documentation
- **[docs/FEXPLORER_USER_GUIDE.md]docs/FEXPLORER_USER_GUIDE.md** - Complete fexplorer guide
- **[docs/PX_USER_GUIDE.md]docs/PX_USER_GUIDE.md** - Complete px guide
- **[docs/WORKFLOWS.md]docs/WORKFLOWS.md** - Combined workflows using both tools ⭐

### Additional Resources
- **[docs/QUICK_START.md]docs/QUICK_START.md** - Quick reference guide
- **[docs/INSTALLATION.md]docs/INSTALLATION.md** - Detailed installation
- **[docs/]docs/** - Complete documentation index

## 🤝 Contributing

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Make your changes with tests
4. Run `cargo fmt && cargo clippy && cargo test`
5. Submit a pull request

## 📄 License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## 🙏 Acknowledgments

Built with these excellent crates:

### Core Dependencies (Both Tools)
- [clap]https://github.com/clap-rs/clap - Command-line argument parsing
- [ignore]https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore - Gitignore support from ripgrep
- [walkdir]https://github.com/BurntSushi/walkdir - Filesystem traversal
- [serde]https://github.com/serde-rs/serde - Serialization framework
- [chrono]https://github.com/chronotope/chrono - Date and time library
- [rayon]https://github.com/rayon-rs/rayon - Data parallelism
- [git2]https://github.com/rust-lang/git2-rs - Git operations via libgit2

### fexplorer-Specific
- [notify]https://github.com/notify-rs/notify - Filesystem notifications

### px-Specific
- [fuzzy-matcher]https://github.com/lotabout/fuzzy-matcher - Fuzzy string matching
- [toml]https://github.com/toml-rs/toml - Configuration parsing

---

**Made with 🦀 and ❤️ by Rust enthusiasts**