ripgrep

So a quick note about a slight difference in grep and ripgrep.

if i want grep to look for specific files you need to do that with following options

grep --include="*.ext" "keyword" location

however this doesn’t directly translate to ripgrep command, ripgrep has one better, ripgrep supports type list, as you can see it has support for a lot of types.

rg --type-list                            
agda: *.agda, *.lagda
aidl: *.aidl
amake: *.bp, *.mk
asciidoc: *.adoc, *.asc, *.asciidoc
asm: *.S, *.asm, *.s
asp: *.ascx, *.ascx.cs, *.ascx.vb, *.aspx, *.aspx.cs, *.aspx.cs
ats: *.ats, *.dats, *.hats, *.sats
avro: *.avdl, *.avpr, *.avsc
awk: *.awk
bazel: *.bzl, BUILD, BUILD.bazel, WORKSPACE
bitbake: *.bb, *.bbappend, *.bbclass, *.conf, *.inc
brotli: *.br
buildstream: *.bst
bzip2: *.bz2, *.tbz2
c: *.[chH], *.[chH].in, *.cats
cabal: *.cabal
cbor: *.cbor
ceylon: *.ceylon
clojure: *.clj, *.cljc, *.cljs, *.cljx
cmake: *.cmake, CMakeLists.txt
coffeescript: *.coffee
config: *.cfg, *.conf, *.config, *.ini
cpp: *.[ChH], *.[ChH].in, *.[ch]pp, *.[ch]pp.in, *.[ch]xx, *.[ch]xx.in, *.cc, *.cc.in, *.hh, *.hh.in, *.inl
creole: *.creole
crystal: *.cr, Projectfile
cs: *.cs
csharp: *.cs
cshtml: *.cshtml
css: *.css, *.scss
csv: *.csv
cython: *.pxd, *.pxi, *.pyx
d: *.d
dart: *.dart
dhall: *.dhall
docker: *Dockerfile*
edn: *.edn
elisp: *.el
elixir: *.eex, *.ex, *.exs
elm: *.elm
erlang: *.erl, *.hrl
fidl: *.fidl
fish: *.fish
fortran: *.F, *.F77, *.F90, *.F95, *.f, *.f77, *.f90, *.f95, *.pfo
fsharp: *.fs, *.fsi, *.fsx
gap: *.g, *.gap, *.gd, *.gi, *.tst
gn: *.gn, *.gni
go: *.go
groovy: *.gradle, *.groovy
gzip: *.gz, *.tgz
h: *.h, *.hpp
haskell: *.c2hs, *.cpphs, *.hs, *.hsc, *.lhs
hbs: *.hbs
hs: *.hs, *.lhs
html: *.ejs, *.htm, *.html
idris: *.idr, *.lidr
java: *.java, *.jsp, *.jspx, *.properties
jinja: *.j2, *.jinja, *.jinja2
jl: *.jl
js: *.js, *.jsx, *.vue
json: *.json, composer.lock
jsonl: *.jsonl
julia: *.jl
jupyter: *.ipynb, *.jpynb
kotlin: *.kt, *.kts
less: *.less
license: *[.-]LICEN[CS]E*, AGPL-*[0-9]*, APACHE-*[0-9]*, BSD-*[0-9]*, CC-BY-*, COPYING, COPYING[.-]*, COPYRIGHT, COPYRIGHT[.-]*, EULA, EULA[.-]*, GFDL-*[0-9]*, GNU-*[0-9]*, GPL-*[0-9]*, LGPL-*[0-9]*, LICEN[CS]E, LICEN[CS]E[.-]*, MIT-*[0-9]*, MPL-*[0-9]*, NOTICE, NOTICE[.-]*, OFL-*[0-9]*, PATENTS, PATENTS[.-]*, UNLICEN[CS]E, UNLICEN[CS]E[.-]*, agpl[.-]*, gpl[.-]*, lgpl[.-]*, licen[cs]e, licen[cs]e.*
lisp: *.el, *.jl, *.lisp, *.lsp, *.sc, *.scm
lock: *.lock, package-lock.json
log: *.log
lua: *.lua
lz4: *.lz4
lzma: *.lzma
m4: *.ac, *.m4
make: *.mak, *.mk, [Gg][Nn][Uu]makefile, [Gg][Nn][Uu]makefile.am, [Gg][Nn][Uu]makefile.in, [Mm]akefile, [Mm]akefile.am, [Mm]akefile.in
mako: *.mako, *.mao
man: *.[0-9][cEFMmpSx], *.[0-9lnpx]
markdown: *.markdown, *.md, *.mdown, *.mkdn
matlab: *.m
md: *.markdown, *.md, *.mdown, *.mkdn
mk: mkfile
ml: *.ml
msbuild: *.csproj, *.fsproj, *.proj, *.props, *.targets, *.vcxproj
nim: *.nim, *.nimble, *.nimf, *.nims
nix: *.nix
objc: *.h, *.m
objcpp: *.h, *.mm
ocaml: *.ml, *.mli, *.mll, *.mly
org: *.org
pascal: *.dpr, *.inc, *.lpr, *.pas, *.pp
pdf: *.pdf
perl: *.PL, *.perl, *.pl, *.plh, *.plx, *.pm, *.t
php: *.php, *.php3, *.php4, *.php5, *.phtml
pod: *.pod
postscript: .eps, .ps
protobuf: *.proto
ps: *.cdxml, *.ps1, *.ps1xml, *.psd1, *.psm1
puppet: *.erb, *.pp, *.rb
purs: *.purs
py: *.py
qmake: *.prf, *.pri, *.pro
qml: *.qml
r: *.R, *.Rmd, *.Rnw, *.r
rdoc: *.rdoc
readme: *README, README*
robot: *.robot
rst: *.rst
ruby: *.gemspec, *.rb, .irbrc, Gemfile, Rakefile
rust: *.rs
sass: *.sass, *.scss
scala: *.sbt, *.scala
sh: *.bash, *.bashrc, *.csh, *.cshrc, *.ksh, *.kshrc, *.sh, *.tcsh, *.zsh, .bash_login, .bash_logout, .bash_profile, .bashrc, .cshrc, .kshrc, .login, .logout, .profile, .tcshrc, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, bash_login, bash_logout, bash_profile, bashrc, profile, zlogin, zlogout, zprofile, zshenv, zshrc
smarty: *.tpl
sml: *.sig, *.sml
soy: *.soy
spark: *.spark
sql: *.psql, *.sql
stylus: *.styl
sv: *.h, *.sv, *.svh, *.v, *.vg
svg: *.svg
swift: *.swift
swig: *.def, *.i
systemd: *.automount, *.conf, *.device, *.link, *.mount, *.path, *.scope, *.service, *.slice, *.socket, *.swap, *.target, *.timer
taskpaper: *.taskpaper
tcl: *.tcl
tex: *.bib, *.cls, *.dtx, *.ins, *.ltx, *.sty, *.tex
textile: *.textile
tf: *.tf
thrift: *.thrift
toml: *.toml, Cargo.lock
ts: *.ts, *.tsx
twig: *.twig
txt: *.txt
vala: *.vala
vb: *.vb
verilog: *.sv, *.svh, *.v, *.vh
vhdl: *.vhd, *.vhdl
vim: *.vim
vimscript: *.vim
webidl: *.idl, *.webidl, *.widl
wiki: *.mediawiki, *.wiki
xml: *.dtd, *.rng, *.sch, *.xjb, *.xml, *.xml.dist, *.xsd, *.xsl, *.xslt
xz: *.txz, *.xz
yacc: *.y
yaml: *.yaml, *.yml
zig: *.zig
zsh: *.zsh, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, zlogin, zlogout, zprofile, zshenv, zshrc
zstd: *.zst, *.zstd

so the new command becomes

rg --type=list_type "keyword" location

so if i am searching in PHP files my code would be

rg --type=php keyword location

till next post

Do you like what you read, What to share it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.