| name | cli-ninja |
| description | Master CLI navigation and code exploration using modern command-line tools. Use this skill when navigating repositories, searching for files/text/code patterns, or working with structured data (JSON/YAML/XML). Provides guidance on fd (file finding), rg (text search), ast-grep (code structure), fzf (interactive selection), jq (JSON), and yq (YAML/XML). |
CLI Ninja
Overview
This skill provides guidance for efficient repository navigation and code exploration using modern CLI tools. Each tool serves a specific purpose: fd for finding files, rg for searching text, ast-grep for understanding code structure, fzf for interactive selection, jq for JSON manipulation, and yq for YAML/XML processing.
Tool Selection Decision Tree
When navigating or exploring a repository, choose the appropriate tool based on the task:
What are you looking for?
├─ FILES by name/path/extension?
│ └─ Use: fd
│ └─ Need to select from results? → Pipe to fzf
│
├─ TEXT/STRINGS in file contents?
│ └─ Use: rg (ripgrep)
│ └─ Need to select from results? → Pipe to fzf
│
├─ CODE STRUCTURE (functions, classes, imports)?
│ └─ Use: ast-grep
│ └─ Need to select from results? → Pipe to fzf
│ └─ Need to refactor/replace? → Use ast-grep --rewrite
│
├─ Working with JSON data?
│ └─ Use: jq
│
└─ Working with YAML or XML data?
└─ Use: yq
Quick Reference Guide
fd - Find Files
Basic patterns:
fd 'pattern'
fd -e py
fd -e 'test.py$'
fd 'pattern' src/
fd -i readme
fd -H '.env'
fd -e py -E '*test*'
Common workflows:
fd config | fzf | xargs $EDITOR
fd -e py -td --changed-within 7d
fd -e db --size +100m
See references/fd-patterns.md for comprehensive patterns and flags.
rg - Search Text/Strings
Basic patterns:
rg 'search_term'
rg -i 'search_term'
rg -w 'word'
rg -C 3 'pattern'
rg -B 2 -A 5 'pattern'
rg -t py 'import'
rg -t rust 'fn main'
Advanced usage:
rg -n 'pattern'
rg -U 'pattern.*spanning.*lines'
rg 'TODO' -g '!*test*'
rg 'pattern' src/ core/
rg --json 'pattern'
Interactive workflows:
rg -l 'TODO' | fzf | xargs $EDITOR
rg --line-number 'pattern' | fzf --preview 'bat --color=always {1} --highlight-line {2}'
See references/rg-patterns.md for regex tips and advanced patterns.
ast-grep - Find Code Structure
Philosophy: ast-grep searches code by structure, not strings. It understands programming language syntax and semantics.
Basic patterns:
Python:
ast-grep --pattern 'def $FUNC($$$)' -l py
ast-grep --pattern 'player.play($$$)' -l py
ast-grep --pattern 'class $CLASS:' -l py
ast-grep --pattern 'from $MOD import $$$' -l py
ast-grep --pattern 'import $MOD' -l py
ast-grep --pattern 'def $FUNC($$$) -> $TYPE:' -l py
JavaScript/TypeScript:
ast-grep --pattern 'function $COMP() { $$$ }' -l tsx
ast-grep --pattern 'const [$STATE, $SETTER] = useState($$$)' -l tsx
ast-grep --pattern 'async function $FUNC($$$) { $$$ }' -l js
ast-grep --pattern 'import $$ from "$MODULE"' -l ts
Rust:
ast-grep --pattern 'fn $FUNC($$$) { $$$ }' -l rs
ast-grep --pattern 'struct $NAME { $$$ }' -l rs
ast-grep --pattern 'impl $TRAIT for $TYPE { $$$ }' -l rs
ast-grep --pattern 'println!($$$)' -l rs
Go:
ast-grep --pattern 'func $FUNC($$$) $$$ { $$$ }' -l go
ast-grep --pattern 'type $NAME struct { $$$ }' -l go
ast-grep --pattern 'func ($RECV $TYPE) $METHOD($$$) $$$ { $$$ }' -l go
ast-grep --pattern 'go $FUNC($$$)' -l go
Zig:
ast-grep --pattern 'pub fn $FUNC($$$) $$$ { $$$ }' -l zig
ast-grep --pattern 'const $NAME = struct { $$$ };' -l zig
ast-grep --pattern 'test "$NAME" { $$$ }' -l zig
ast-grep --pattern 'try $EXPR' -l zig
Ruby:
ast-grep --pattern 'def $METHOD($$$); $$$; end' -l rb
ast-grep --pattern 'class $CLASS; $$$; end' -l rb
ast-grep --pattern '$EXPR do |$PARAM|; $$$; end' -l rb
ast-grep --pattern 'get "$PATH", to: "$HANDLER"' -l rb
Refactoring with ast-grep:
ast-grep --pattern 'old_function($$$)' --rewrite 'new_function($$$)' -l py --interactive
ast-grep --pattern 'api.v1.$METHOD($$$)' --rewrite 'api.v2.$METHOD($$$)' -l py
ast-grep --pattern 'var $VAR = $EXPR' --rewrite 'const $VAR = $EXPR' -l js
Interactive workflows:
ast-grep --pattern 'def $FUNC($$$)' -l py | fzf | cut -d: -f1 | xargs $EDITOR
rg 'TODO|FIXME' | fzf
See references/ast-grep-guide.md for comprehensive patterns across all languages.
fzf - Interactive Selection
Basic usage:
command | fzf
command | fzf -m
command | fzf --preview 'bat {}'
Preview configurations:
fd -t f | fzf --preview 'bat --color=always {}'
rg --line-number 'pattern' | fzf --preview 'bat --color=always {1} --highlight-line {2}'
fd -e json | fzf --preview 'jq . {}'
fzf --preview 'cat {}' --preview-window=right:50%
Keybindings:
fzf --bind 'ctrl-y:execute-silent(echo {} | pbcopy)'
See references/fzf-workflows.md for advanced interactive workflows.
jq - JSON Processing
Basic queries:
jq . file.json
jq '.name' file.json
jq '.[0]' file.json
jq '.user.name' file.json
jq '.[] | .name' file.json
Common transformations:
jq '.users[] | select(.active == true)' file.json
jq '.users | map(.name)' file.json
jq '.users | sort_by(.age)' file.json
jq 'group_by(.category)' file.json
jq '.items | length' file.json
jq 'keys' file.json
Advanced usage:
jq '.users[] | select(.age > 18) | .name' file.json
jq '{name: .firstName, email: .emailAddress}' file.json
jq -s '.[0] + .[1]' file1.json file2.json
curl -s https://api.example.com/data | jq '.results[]'
See references/jq-cookbook.md for comprehensive transformations.
yq - YAML/XML Processing
YAML queries:
yq . file.yaml
yq '.name' file.yaml
yq '.services.web.image' docker-compose.yml
yq '.dependencies[]' file.yaml
yq -o json . file.yaml
XML queries:
yq -p xml . file.xml
yq -p xml '.root.element' file.xml
yq -p xml -o json . file.xml
Common operations:
yq '.version = "2.0"' file.yaml
yq '. *= load("other.yaml")' file.yaml
yq '.items[] | select(.enabled == true)' file.yaml
See references/yq-examples.md for YAML/XML processing patterns.
Combination Workflows
Real-world tasks often combine multiple tools:
1. Find and Edit Files with Context
rg -l 'def process_data' -t py | fzf --preview 'rg -C 5 "def process_data" {}' | xargs $EDITOR
2. Code Refactoring Workflow
ast-grep --pattern 'old_function($$$)' -l py | fzf -m
ast-grep --pattern 'old_function($$$)' --rewrite 'new_function($$$)' -l py --interactive
3. Interactive Configuration Explorer
fd -e json -e yaml | fzf --preview 'bat --color=always {} --style=numbers'
fd -e json | fzf --preview 'jq . {}'
fd -e yaml | fzf --preview 'yq . {}'
4. Find Related Code
CLASS=$(ast-grep --pattern 'class $NAME:' -l py | fzf | cut -d: -f2)
rg -w "$CLASS" --type py
5. Dependency Analysis
ast-grep --pattern 'from mymodule import $$$' -l py -t python
rg 'importlib.*mymodule' -t py
6. Multi-File Search and Replace
rg -l 'TODO.*urgent' | fzf -m | xargs sed -i '' 's/TODO.*urgent/DONE/g'
7. Code Structure Analysis
ast-grep --pattern 'def $FUNC($$$)' -l py src/module.py | wc -l
ast-grep --pattern 'def $FUNC($A, $B, $C, $D, $E, $$$)' -l py
See scripts/combo-search.sh and scripts/interactive-code-finder.sh for reusable combination workflows.
Best Practices
Performance Tips
-
Use the right tool for the job:
- File names →
fd
- Text content →
rg
- Code structure →
ast-grep
-
Narrow your search scope:
rg 'pattern' src/
rg 'pattern' -t py src/
-
Use .gitignore respect:
- Both
fd and rg respect .gitignore by default
- Use
-u or --no-ignore to override when needed
Pattern Matching Tips
-
ast-grep patterns:
- Use
$VAR for single identifiers
- Use
$$$ for arbitrary code sequences
- Use
$$ for statement lists
-
ripgrep regex:
- Use
-F for literal strings (faster)
- Use
-w for whole words
- Use
\b for word boundaries
-
fzf fuzzy matching:
- Space for AND search:
foo bar matches files with both
| for OR search: foo|bar
^ for prefix match, $ for suffix match
Debugging Searches
rg --debug 'pattern' 2>&1 | head -20
ast-grep --pattern 'old' --rewrite 'new' --interactive
echo '{"name":"test"}' | jq .
echo '{"name":"test"}' | jq '.name'
Resources
This skill includes bundled resources to support CLI navigation:
scripts/
Example scripts demonstrating tool combinations:
combo-search.sh - Common combination workflows
interactive-code-finder.sh - Interactive ast-grep + fzf workflow
references/
Comprehensive guides for each tool:
fd-patterns.md - File finding patterns and flags
rg-patterns.md - Text search patterns and regex tips
ast-grep-guide.md - Code structure patterns for Python, Zig, Go, Ruby, JS/TS, Rust
fzf-workflows.md - Interactive selection and preview configurations
jq-cookbook.md - JSON transformations and filters
yq-examples.md - YAML/XML processing examples