ripgrep - Max Fang's Notes# ripgrep
## Intro post and guide to [[ripgrep]]
https://blog.burntsushi.net/ripgrep/
## Installation
### Install with [[Cargo]]
```bash
cargo install ripgrep
```
### [Install on Ubuntu 18.10 or newer](https://github.com/BurntSushi/ripgrep#installation)
```bash
sudo apt install ripgrep
```
### With [[Vim]] and CtrlP
https://www.philipbradley.net/posts/2017-03-29-ripgrep-with-ctrlp-and-vim/
```vim
if executable('rg')
let g:ctrlp_user_command = 'rg --files %s'
let g:ctrlp_use_caching = 0
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_switch_buffer = 'et'
endif
```
### Pipe [[ripgrep]] output into [[Vim]]
```bash
$ rg OrderBuffer -l
src/main.rs
src/micro/mod.rs
$ vim -p `!!` $ vim -p `rg OrderBuffer -l`
```
- `-p` opens in tabs, `-O` opens in vertical splits
### List files
```bash
$ rg --files
ConfigExample.toml
Eutykhia.iml
src/watcher/tests.rs
src/watcher/mod.rs
src/director/tests.rs
src/director/mod.rs
```
```bash
$ rg --files --no-ignore | rg CURRENT
log/tyche_rCURRENT.log
target/doc/libc/constant.MCL_CURRENT.html
target/doc/libc/unix/bsd/apple/constant.MCL_CURRENT.html
```
### Search filenames
```bash
$ rg --files | rg filename
```
### List number of matches with `-c`
https://github.com/BurntSushi/ripgrep/issues/411
```bash
rg PNLv4 | rg -c "random=true"
```
### Literal search with `-F`
Doesn't work well with piping
Demo:
```
echo "[2021-11-05 21:26:24.581118 INFO] [eutykhia::watcher] PNLv4.8: Made $0.077110557600 (Add LRC): {funding_rate=0.000039,random=false,target_basis=0.00072,chunk_size=1000,compete_ratio=0.7,tick_buffer=7,usd_size=116.3733449669852512987012987,hedge_rt_latency=200,usd_order_size=115.74315,preconf_cancels=true,time_spent=3,volume_usd=29.86920,blank_fill=false,}" > test.log
```
```bash
# outputs
tail -n 1 test.log
# outputs
tail -n 1 test.log | rg -F blank_fill=false
# no output
tail -n 1 test.log | rg -F blank_fill=false | rg -F $
# outputs
tail -n 1 test.log | rg -F blank_fill=false | rg $
# outputs
tail -n 1 test.log | rg -F blank_fill=false | rg "
quot;
```
Another test string:
```
echo "[2021-11-05 21:31:35.342390 INFO] [eutykhia::watcher] PNLv4.8: Made $0.009877259925 (Add LRC): {funding_rate=0.000041,random=false,target_basis=0.00072,chunk_size=1000,compete_ratio=0.7,tick_buffer=7,usd_size=116.3733449669852512987012987,hedge_rt_latency=225,usd_order_size=85.87395,preconf_cancels=true,time_spent=0,volume_usd=16.17915,blank_fill=false,}" > test.log
```
```shell
# outputs
tail test.log | rg PNLv
# outputs
tail -F log/tyche_rCURRENT.log | rg PNLv
# outputs
tail test.log | rg PNLv | rg -vF blank_fill=true
# no output
tail -F log/tyche_rCURRENT.log | rg PNLv | rg -vF blank_fill=true
# doesn't appear to output with -F
tail -n 1 test.log | rg -F blank_fill=false | rg $
```
Appears to work:
```shell
# Top pane
tail -F log/tyche_rCURRENT.log | rg -F blank_fill=false
# Works sometimes, but only prints a subset of the preceding
tail -F log/tyche_rCURRENT.log | rg -F blank_fill=false | rg PNLv
# Testing
tail -F log/tyche_rCURRENT.log | rg INFO | rg PNLv
```