file-search ยท diff

git:20251220.6c081e5 to git:20251221.9f26d95

43 added, 154 removed. Audit A to A.

---
name: file-search
description: "Modern file and content search using fd, ripgrep (rg), and fzf. Triggers on: fd, ripgrep, rg, find files, search code, fzf, fuzzy find, search codebase."
compatibility: "Requires fd, ripgrep (rg), and optionally fzf. Install: brew install fd ripgrep fzf (macOS)."
allowed-tools: "Bash"
---
# File Search
- Modern file and content search using fd, ripgrep (rg), and fzf for interactive selection.
+ Modern file and content search.
- ## fd - Find Files (Better than find)
+ ## fd - Find Files
- ### Basic Usage
```bash
- # Find by name (case-insensitive by default)
+ # Find by name
fd config # Files containing "config"
- fd "\.ts$" # TypeScript files (regex)
- fd -e py # Python files by extension
-
- # Multiple extensions
- fd -e js -e ts # JS and TS files
- fd -e md -e txt # Markdown and text files
- ```
+ fd -e py # Python files
- ### Filtering
- ```bash
# By type
fd -t f config # Files only
fd -t d src # Directories only
- fd -t l # Symlinks only
- # By depth
- fd -d 2 config # Max 2 levels deep
- fd --min-depth 2 config # At least 2 levels deep
-
- # Include hidden/ignored
- fd -H config # Include hidden files
- fd -I config # Include .gitignore'd files
- fd -HI config # Include both
- ```
-
- ### Exclusion
- ```bash
- # Exclude patterns
- fd -E "*.min.js" -E "dist/" # Exclude minified and dist
- fd -E node_modules # Exclude node_modules
- fd config -E "*.bak" # Find config, exclude backups
- ```
+ # Exclude
+ fd -E node_modules # Exclude directory
+ fd -E "*.min.js" # Exclude pattern
- ### Execute Commands
- ```bash
- # Run command on each result
- fd -e py -x wc -l # Line count for each Python file
- fd -e ts -x bat {} # View each TypeScript file with bat
- fd -e json -x jq . {} # Pretty print each JSON file
+ # Execute command
+ fd -e py -x wc -l # Line count per file
```
- ## ripgrep (rg) - Search Content (Better than grep)
+ ## rg - Search Content
- ### Basic Usage
```bash
# Simple search
- rg "TODO" # Find TODO in all files
- rg "function \w+" # Regex pattern
+ rg "TODO" # Find TODO
rg -i "error" # Case-insensitive
- rg -w "log" # Word boundary (not "catalog")
- ```
- ### File Filtering
- ```bash
- # By type
- rg -t py "import" # Search Python files only
- rg -t js -t ts "async" # JS and TS files
- rg --type-list # Show all known types
-
- # By glob
- rg -g "*.tsx" "useState" # Search .tsx files
- rg -g "!*.test.*" "fetch" # Exclude test files
- rg -g "src/**" "config" # Only in src directory
- ```
+ # By file type
+ rg -t py "import" # Python files only
+ rg -t js -t ts "async" # JS and TS
- ### Context and Format
- ```bash
- # Show context lines
- rg -C 3 "function" # 3 lines before and after
- rg -B 2 -A 5 "class" # 2 before, 5 after
+ # Context
+ rg -C 3 "function" # 3 lines before/after
- # Output format
+ # Output modes
rg -l "TODO" # File names only
rg -c "TODO" # Count per file
- rg --json "TODO" # JSON output
- rg -n "TODO" # With line numbers (default)
```
- ### Advanced Patterns
- ```bash
- # Multiline
- rg -U "class.*\n.*constructor" # Across lines
-
- # Fixed strings (no regex)
- rg -F "[]" # Literal brackets
-
- # Invert match
- rg -v "console.log" # Lines NOT containing
-
- # Replace (preview)
- rg "oldFunc" -r "newFunc" # Show replacements (use sd to apply)
- ```
-
## fzf - Interactive Selection
- ### Basic Workflows
```bash
- # Find and open file
- fd | fzf # Select file interactively
- fd -e py | fzf # Select from Python files
-
- # Find and edit
- nvim $(fd -e ts | fzf) # Open selected in nvim
- code $(fd | fzf -m) # Open multiple in VS Code
- ```
+ # Find and select
+ fd | fzf
- ### With Preview
- ```bash
- # Preview with bat
+ # With preview
fd | fzf --preview 'bat --color=always {}'
- # Preview with rg context
- rg -l "TODO" | fzf --preview 'rg -C 3 "TODO" {}'
- ```
-
- ### Multi-Select
- ```bash
- # Select multiple (Tab to mark, Enter to confirm)
- fd -e ts | fzf -m # Multi-select mode
- fd -e ts | fzf -m | xargs rm # Delete selected
- ```
-
- ### Combined Workflows
- ```bash
- # Fuzzy grep: search content, select file, open at line
- rg -n "pattern" | fzf --preview 'bat {1} --highlight-line {2}'
-
- # Kill process interactively
- procs | fzf | awk '{print $1}' | xargs kill
-
- # Git branch checkout
- git branch | fzf | xargs git checkout
-
- # Git log with preview
- git log --oneline | fzf --preview 'git show --color=always {1}'
+ # Multi-select
+ fd -e ts | fzf -m | xargs code
```
## Combined Patterns
- ### Find and Search
```bash
- # Find Python files, search for pattern
+ # Find files, search content
fd -e py -x rg "async def" {}
- # Search specific directories
- rg "import" $(fd -t d src lib)
- ```
-
- ### Find, Select, Act
- ```bash
- # Interactive file deletion
- fd -t f "\.bak$" | fzf -m | xargs rm -i
-
- # Interactive config editing
- fd -g "*.config.*" | fzf --preview 'bat {}' | xargs nvim
+ # Search, select, open
+ rg -l "pattern" | fzf --preview 'rg -C 3 "pattern" {}' | xargs vim
```
- ### Codebase Exploration
- ```bash
- # Find all entry points
- rg -l "^(export )?function main|^if __name__"
-
- # Find all TODO/FIXME with context
- rg -C 2 "TODO|FIXME|HACK|XXX"
+ ## Quick Reference
- # Find unused exports (basic)
- rg "export (const|function|class) (\w+)" -o -r '$2' | sort | uniq
- ```
+ | Task | Command |
+ |------|---------|
+ | Find TS files | `fd -e ts` |
+ | Find in src | `fd -e ts src/` |
+ | Search pattern | `rg "pattern"` |
+ | Search in type | `rg -t py "import"` |
+ | Files with match | `rg -l "pattern"` |
+ | Count matches | `rg -c "pattern"` |
+ | Interactive | `fd \| fzf` |
+ | With preview | `fd \| fzf --preview 'bat {}'` |
## Performance Tips
| Tip | Why |
|-----|-----|
- | Both respect `.gitignore` | Automatically skip node_modules, dist, etc. |
- | Use `-t` over `-g` when possible | Type flags are faster than globs |
- | Narrow the path | `rg pattern src/` faster than `rg pattern` |
- | Use `-F` for literal strings | Avoids regex engine overhead |
- | Add `-u` for unignored only when needed | Hidden files slow things down |
+ | Both respect `.gitignore` | Auto-skip node_modules, dist |
+ | Use `-t` over `-g` | Type flags are faster |
+ | Narrow the path | `rg pattern src/` faster |
+ | Use `-F` for literals | Avoids regex overhead |
- ## Quick Reference
+ ## Additional Resources
- | Task | Command |
- |------|---------|
- | Find TS files | `fd -e ts` |
- | Find in src only | `fd -e ts src/` |
- | Search for pattern | `rg "pattern"` |
- | Search in type | `rg -t py "import"` |
- | Files containing | `rg -l "pattern"` |
- | Count matches | `rg -c "pattern"` |
- | Interactive select | `fd \| fzf` |
- | Multi-select | `fd \| fzf -m` |
- | Preview files | `fd \| fzf --preview 'bat {}'` |
+ For detailed patterns, load:
+ - `./references/advanced-workflows.md` - Git integration, shell functions, power workflows