| name | cli-productivity-3-ripgrep-rg-fast-search |
| description | Sub-skill of cli-productivity: 3. ripgrep (rg) - Fast Search (+1). |
| version | 1.0.0 |
| category | operations |
| type | reference |
| scripts_exempt | true |
3. ripgrep (rg) - Fast Search (+1)
3. ripgrep (rg) - Fast Search
Basic Usage:
rg "function"
rg -i "error"
rg -n "TODO"
rg --type py "import"
rg -t js "require"
rg "pattern" --glob '!*.min.js'
rg "pattern" --glob '!node_modules'
Advanced ripgrep:
rg -C 3 "error"
rg -B 2 "error"
rg -A 2 "error"
rg -F "func()"
rg -w "log"
rg -e "pattern1" -e "pattern2"
rg -l "TODO"
rg -c "TODO"
rg -v "DEBUG"
rg "old" --replace "new"
rg --json "pattern" | jq '.'
rg --stats "pattern"
ripgrep Functions:
rgs() {
rg --color=always --line-number "$1" | fzf --ansi --preview 'bat --color=always $(echo {} | cut -d: -f1) --highlight-line $(echo {} | cut -d: -f2)'
}
rge() {
local selection
selection=$(rg --color=always --line-number "$1" | fzf --ansi)
if [[ -n "$selection" ]]; then
local file=$(echo "$selection" | cut -d: -f1)
local line=$(echo "$selection" | cut -d: -f2)
${EDITOR:-vim} "+$line" "$file"
fi
}
todos() {
rg --color=always "TODO|FIXME|HACK|XXX" "${1:-.}" | fzf --ansi
}
funcs() {
rg --color=always "^(def |function |async function |const .* = |class )" "${1:-.}" | fzf --ansi
}
4. fd - Fast Find
Basic Usage:
fd "readme"
fd -e md
fd -e py -e js
fd -t d "src"
fd -t f "config"
fd -E node_modules -E .git
fd -H "config"
fd -e log -x rm {}
fd -e py -x wc -l {}
fd Functions:
fdp() {
fd "$@" | fzf --preview 'bat --color=always {} 2>/dev/null || exa --tree --level=2 --color=always {}'
}
fde() {
local file
file=$(fd -t f "$@" | fzf --preview 'bat --color=always {}')
[[ -n "$file" ]] && ${EDITOR:-vim} "$file"
}
fdlarge() {
local size="${1:-100M}"
fd -t f -S +"$size" | xargs ls -lh | sort -k5 -h
}
fdrecent() {
local days="${1:-7}"
fd -t f --changed-within "${days}d"
}
fddup() {
fd -t f | sort | uniq -d
}