127 lines
2.4 KiB
Markdown
127 lines
2.4 KiB
Markdown
# ripgrep (rg)
|
|
|
|
Remplaçant de *grep*
|
|
|
|
https://github.com/BurntSushi/ripgrep
|
|
|
|
|
|
|
|
##### Installation:
|
|
|
|
```bash
|
|
$ brew install ripgrep
|
|
```
|
|
|
|
##### Utilisation:
|
|
|
|
```bash
|
|
$ rg PATH ~/.zshrc
|
|
```
|
|
|
|
<img src="/Users/bruno/Documents/docs/docs/Linux/rg.png" alt="rg" style="zoom:50%;" />
|
|
|
|
```bash
|
|
# regex ('core' plus 1 ou plusiers lettres)
|
|
$ rg 'core\w+' ~/.zshrc
|
|
22:PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH
|
|
25:coreutils=false
|
|
|
|
# regex ('core' plus 0 ou plusiers lettres)
|
|
$ rg 'core\w*' ~/.zshrc
|
|
22:PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH
|
|
25:coreutils=false
|
|
|
|
# string
|
|
$ rg -F 'eval "$(' ~/.zshrc
|
|
83:eval "$(zoxide init --cmd j zsh)"
|
|
107:eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
|
|
```
|
|
|
|
[https://docs.rs/regex/*/regex/#syntax](https://docs.rs/regex/*/regex/#syntax)
|
|
|
|
rg dans tout un répertoire:
|
|
|
|
```bash
|
|
$ rg '#!'
|
|
handbrake-batchconvert.sh
|
|
1:#!/bin/sh
|
|
|
|
composer.sh
|
|
1:#!/bin/bash
|
|
|
|
tmutil.sh
|
|
1:#!/bin/bash
|
|
```
|
|
|
|
```bash
|
|
$ rg '#!' Scripts
|
|
Scripts/kymsu2/kymsu2.sh
|
|
1:#!/usr/bin/env bash
|
|
|
|
Scripts/sonos/test.sh
|
|
1:#!/usr/bin/env bash
|
|
```
|
|
|
|
En l'absence de chemin, rg cherche dans le répertoire courant.
|
|
|
|
##### Filtre manuel:
|
|
|
|
```bash
|
|
# Rechercher uniquement dans les fichiers .sh
|
|
rg echo -g '*.sh'
|
|
|
|
# Rechercher partout sauf dans les fichiers .sh
|
|
rg echo -g '!*.sh'
|
|
```
|
|
|
|
##### File types
|
|
|
|
```bash
|
|
$ rg --type-list
|
|
...
|
|
config: *.cfg, *.conf, *.config, *.ini
|
|
md: *.markdown, *.md, *.mdown, *.mkdn
|
|
php: *.php, *.php3, *.php4, *.php5, *.phtml
|
|
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
|
|
...
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
# Recherche dans les fichiers shell .bashrc, .zshrc...
|
|
|
|
$ rg 'eval' --type sh ~/
|
|
# ou
|
|
$ rg 'eval' -tsh ~/
|
|
/Users/bruno/.bash_profile
|
|
72:eval "$(thefuck --alias)"
|
|
/Users/bruno/.zprofile
|
|
1:eval "$(/opt/homebrew/bin/brew shellenv)"
|
|
...
|
|
|
|
# Recherche partout sauf dans les fichiers shell .bashrc, .zshrc...
|
|
|
|
$ rg 'eval' --type-not sh ~/
|
|
# ou
|
|
$ rg 'eval' -Tsh ~/
|
|
```
|
|
|
|
##### Remplacement:
|
|
|
|
```bash
|
|
# recherche / remplacement mot pour mot
|
|
$ rg fast README.md --replace FAST
|
|
$ rg fast README.md -r FAST
|
|
|
|
# remplacer toute une ligne
|
|
$ rg '^.*fast.*$' README.md -r FAST
|
|
```
|
|
|
|
##### Fichier de configuration:
|
|
|
|
```bash
|
|
$ cat $HOME/.ripgreprc
|
|
```
|
|
|