rfgrep 0.2.1

Recursive file grep utility with advanced filtering - search, list, and analyze text files with regex support
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
# rfgrep  

A command-line utility for recursively searching and listing files with advanced filtering capabilities. Built in Rust.

[<img alt="crates.io" src="https://img.shields.io/crates/v/rfgrep.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/rfgrep)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-rfgrep-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/rfgrep)
[![CI](https://github.com/kh3rld/rfgrep/actions/workflows/ci.yml/badge.svg)](https://github.com/kh3rld/rfgrep/actions/workflows/ci.yml)
[![License](https://img.shields.io/github/license/kh3rld/rfgrep)](https://github.com/kh3rld/rfgrep/blob/main/LICENSE)

## Features

- **Advanced Search**
  - Regex, plain text, and whole-word matching
  - Recursive directory traversal
  - Binary file detection
  - Extension filtering
  - Size limits

- **File Listing**
  - Detailed/simple output formats
  - Extension statistics
  - Size filtering
  - Hidden file handling

- **Utilities**
  - Clipboard copy support
  - Dry-run mode
  - Logging to file
  - Progress indicators

<!-- ## Performance

![Benchmark Results](https://github.com/kh3rld/rfgrep/raw/main/benches/comparison.png)

Latest benchmarks (Linux x86_64):
```bash
# Updated automatically by CI
cat benches/latest.txt -->

## Installation

Assuming you have [Rust installed][Rust], run:

[Rust]: https://www.rust-lang.org/

### Via Cargo

```bash
cargo install rfgrep
```

### From GitHub
```bash
cargo install --git https://github.com/kh3rld/rfgrep.git
```

### From Source

```bash
git clone https://github.com/kh3rld/rfgrep.git
cargo build --release
```

### Installing Man Pages

After installing rfgrep, you can install the comprehensive man pages:

#### System-wide Installation (requires sudo)
```bash
cd man
sudo make install
```

#### User Installation (no sudo required)
```bash
cd man
make install-user
```

Then add to your shell profile (`.bashrc`, `.zshrc`, etc.):
```bash
export MANPATH=$MANPATH:$HOME/.local/share/man
```

### Installing Shell Completions

rfgrep supports tab completion for all major shells:

#### Bash
```bash
# Generate and source completion
rfgrep completions bash >> ~/.bashrc
source ~/.bashrc
```

#### Zsh
```bash
# Generate completion file
rfgrep completions zsh > ~/.zsh/completions/_rfgrep
# Add to .zshrc
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
autoload -U compinit && compinit
```

#### Fish
```bash
# Generate and install
rfgrep completions fish --install --user
```

#### PowerShell
```bash
# Generate and import
rfgrep completions powershell > rfgrep-completion.ps1
. rfgrep-completion.ps1
```

## Usage

### Basic Search

```bash
rfgrep search "pattern"
```

### Search with Options

```bash
rfgrep search "pattern" \
    --mode regex \
    --extensions rs,toml \
    --max-size 5 \
    --skip-binary \
    --copy
```

### File Listing

```bash
# Simple list
rfgrep list

# Detailed view
rfgrep list --long --recursive

# With filters
rfgrep list --extensions rs,toml --max-size 10 --show-hidden
```

## Documentation

### Man Pages

After installation, comprehensive man pages are available:

```bash
# Main man page
man rfgrep

# Command-specific man pages
man rfgrep-search
man rfgrep-interactive
man rfgrep-list
man rfgrep-completions
```

The man pages include:
- Complete command reference
- Detailed option descriptions
- Practical examples
- Performance tips
- Troubleshooting guides

### Shell Completions

Once installed, tab completion provides:
- Command completion (`rfgrep <TAB>`)
- Option completion (`rfgrep search --<TAB>`)
- Extension completion (`--extensions <TAB>`)
- File path completion (`src/<TAB>`)

### Troubleshooting

#### Man Pages Not Found
```bash
# Check if man pages are installed
ls ~/.local/share/man/man1/rfgrep*

# Add to shell profile if needed
echo 'export MANPATH=$MANPATH:$HOME/.local/share/man' >> ~/.bashrc
```

#### Completions Not Working
```bash
# Regenerate completions
rfgrep completions bash > ~/.bash_completion.d/rfgrep

# Reload shell configuration
source ~/.bashrc

# For zsh, ensure completion directory exists
mkdir -p ~/.zsh/completions
rfgrep completions zsh > ~/.zsh/completions/_rfgrep

# For fish, install to user directory
rfgrep completions fish --install --user
```

#### Performance Issues
```bash
# Use dry-run to preview
rfgrep search "pattern" --dry-run

# Skip binary files
rfgrep search "pattern" --skip-binary

# Limit file size
rfgrep search "pattern" --max-size 10

# Use specific extensions
rfgrep search "pattern" --extensions rs,py,js
```

#### Shell-Specific Troubleshooting

**Bash:**
```bash
# Check if completion is loaded
complete -p | grep rfgrep

# Manual installation
rfgrep completions bash >> ~/.bashrc
source ~/.bashrc
```

**Zsh:**
```bash
# Check completion directory
ls ~/.zsh/completions/_rfgrep

# Reload completions
autoload -U compinit && compinit
```

**Fish:**
```bash
# Check if completion is installed
ls ~/.config/fish/completions/rfgrep.fish

# Manual installation
rfgrep completions fish > ~/.config/fish/completions/rfgrep.fish
```

## Command Reference

### Global Options

| Option       | Description                     |
|--------------|---------------------------------|
| `--log PATH` | Write logs to specified file    |
| `--path DIR` | Base directory (default: `.`)   |

### Search Command

| Option             | Description                         |
|--------------------|-------------------------------------|
| `--mode MODE`      | Search mode: regex/text/word        |
| `--extensions EXT` | Comma-separated file extensions     |
| `--max-size MB`    | Skip files larger than specified MB |
| `--skip-binary`    | Skip binary files                   |
| `--dry-run`        | Preview files without processing    |
| `--copy`           | Copy results to clipboard           |

### List Command

| Option             | Description                         |
|--------------------|-------------------------------------|
| `--extensions EXT` | Comma-separated file extensions     |
| `--long`           | Detailed output format              |
| `--recursive`      | Recursive directory traversal       |
| `--show-hidden`    | Include hidden files/directories    |
| `--max-size MB`    | Skip files larger than specified MB |
| `--skip-binary`    | Skip binary files                   |

## Examples

1. Find all Rust files containing "HashMap":

```bash
rfgrep search "HashMap" --extensions rs
```

1. List all Markdown files under 1MB:

```bash
rfgrep list --extensions md --max-size 1
```

1. Search with regex and copy to clipboard:

```bash
rfgrep search "fn\s+\w+\s*\(" --mode regex --copy
```

## Performance Tips

- Use `--skip-binary` to avoid unnecessary file checks
- Limit scope with `--extensions` and `--max-size`
- For large directories, `--dry-run` first to preview

## Advanced Usage

### Interactive Mode
```bash
# Start interactive search
rfgrep interactive "pattern"

# Interactive search with specific algorithm
rfgrep interactive "pattern" --algorithm boyer-moore

# Interactive search in specific file types
rfgrep interactive "pattern" --extensions rs,py
```

### Output Formats
```bash
# JSON output for programmatic processing
rfgrep search "pattern" --output-format json

# XML output for structured data
rfgrep search "pattern" --output-format xml

# HTML output for web display
rfgrep search "pattern" --output-format html

# Markdown output for documentation
rfgrep search "pattern" --output-format markdown
```

### Search Algorithms
```bash
# Boyer-Moore (fast for plain text)
rfgrep search "pattern" --algorithm boyer-moore

# Regular expression
rfgrep search "pattern" --algorithm regex

# Simple linear search
rfgrep search "pattern" --algorithm simple
```

## Verification

### Test Man Pages
```bash
# Verify man pages are accessible
man rfgrep
man rfgrep-search
man rfgrep-interactive
man rfgrep-list
man rfgrep-completions
```

### Test Shell Completions
```bash
# Bash: Type 'rfgrep ' and press TAB
rfgrep <TAB>

# Zsh: Type 'rfgrep ' and press TAB
rfgrep <TAB>

# Fish: Type 'rfgrep ' and press TAB
rfgrep <TAB>
```

### Test Basic Functionality
```bash
# Test search functionality
rfgrep search "test" --extensions rs

# Test list functionality
rfgrep list --extensions rs

# Test interactive mode
rfgrep interactive "test" --extensions rs
```

### Clipboard behavior in CI/headless environments

Note: the `--copy` option attempts to use the system clipboard and may fail in headless CI environments (X11/Wayland not available). In those environments run without `--copy` or provide a virtual display (Xvfb) or configure your CI to provide a clipboard service. The application will log a warning if the clipboard operation times out.

### Automated Testing
```bash
# Test shell completions
./test_completions.sh

# Test man pages
./test_man_pages.sh
```

## Contributing

Contributions are welcome! Please open an issue or PR for any:
- Bug reports
- Feature requests
- Performance improvements