Ripgrep: Difference between revisions

From wikinotes
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 10: Line 10:
|-
|-
| official docs || https://github.com/BurntSushi/ripgrep
| official docs || https://github.com/BurntSushi/ripgrep
|-
| configuration docs || https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file
|-
|-
|}
|}
Line 18: Line 20:
{| class="wikitable"
{| class="wikitable"
|-
|-
| <code>${ANYWHERE}/.ripgreprc</code> || subdirectory specific config
| <code>RIPGREP_CONFIG_PATH=${ANYWHERE}/.ripgreprc</code> || optional config file
|-
|-
| <code>${ANYWHERE}/.rgignore</code> || subdirectory specific ignore files
| <code>${ANYWHERE}/.rgignore</code> || subdirectory specific ignore files
Line 56: Line 58:
== .ripgreprc ==
== .ripgreprc ==
<blockquote>
<blockquote>
Any arguments you'd like to always be passed to ripgrep, dump in a ripgreprc.<br>
This is not read automatically, you must point to it with the envvar <code>$RIPGREP_CONFIG_PATH</code>.


example
<syntaxhighlight lang="bash">
# ./.ripgreprc
--sortr
path
</syntaxhighlight>
</blockquote><!-- .ripgreprc -->
</blockquote><!-- .ripgreprc -->
</blockquote><!-- Configuration -->
</blockquote><!-- Configuration -->

Latest revision as of 18:16, 19 June 2022

A faster alternative to grep.
Can also perform search/replace.

ripgrep is restricted to single-lines, and does not support lookahead/lookbehind.
If you need these features checkout universal code grep or silversearcher.

Documentation

official docs https://github.com/BurntSushi/ripgrep
configuration docs https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file

Locations

RIPGREP_CONFIG_PATH=${ANYWHERE}/.ripgreprc optional config file
${ANYWHERE}/.rgignore subdirectory specific ignore files

Tutorials

learnbyexample (cookbook) https://learnbyexample.github.io/substitution-with-ripgrep/

Usage

rg --pretty search | less -Ri  # pipe rg to less
rg -g '*.md' search            # search files matching '*.md' for text 'email'
rg -g '!*/test/*' search       # exclude paths matching */test/* (-g can be used multiple times)
rg -i search                   # case insensitive search
rg -uuu search                 # ignore .gitignore, .ignore, ...

# search files from rg
rg 'search' $(rg -l other_search)

# search files from `find`
find . -type f -path '*/mutations/*.rb' -print0 \
  | xargs -0 rg 'search'

Configuration

.ripgreprc

Any arguments you'd like to always be passed to ripgrep, dump in a ripgreprc.
This is not read automatically, you must point to it with the envvar $RIPGREP_CONFIG_PATH.

example

# ./.ripgreprc
--sortr
path