Show HN: frep – fastest find-and-replace CLI

4 months ago 9

frep is a fast find-and-replace tool. To replace the string "before" with the string "after" in the current directory:

There are a number of command-line flags to change the behaviour of frep, such as:

  • --fixed-strings (-f) to search without regex
  • --advanced-regex (-a) to use advanced regex features such as negative lookahead (not enabled by default for improved performance)
  • --include-files (-I) and --exclude-files (-E) to include or exclude files and directories using glob matching. For instance, -I "*.rs, *.py" matches all files with the .rs or .py extensions, and -E "env/**" excludes all files in the env directory

Run frep --help to see the full list of flags.

frep is fast. Compared against other tools that also respect ignore files such as .gitignore, it is the fastest in many scenarios. Here is a benchmark for comparison, performing a find and replace across the entire Linux kernel repo, finding and replacing the string "before" with "after":

Command Mean [s] Min [s] Max [s] Relative
frep 4.740 ± 0.135 4.608 4.917 1.00
ripgrep + sd 5.255 ± 0.207 5.028 5.483 1.11 ± 0.05
fd + sd 10.010 ± 0.000 10.010 10.011 2.11 ± 0.06

On macOS and Linux, you can install frep using Homebrew:

brew install thomasschafer/tap/frep

Download the appropriate binary for your system from the releases page:

Platform Architecture Download file
Linux Intel/AMD *-x86_64-unknown-linux-musl.tar.gz
Linux ARM64 *-aarch64-unknown-linux-musl.tar.gz
macOS Apple Silicon *-aarch64-apple-darwin.tar.gz
macOS Intel *-x86_64-apple-darwin.tar.gz
Windows x64 *-x86_64-pc-windows-msvc.zip

After downloading, extract the binary and move it to a directory in your PATH.

Ensure you have cargo installed (see here), then run:

Ensure you have cargo installed (see here), then run the following commands:

git clone [email protected]:thomasschafer/frep.git cd frep cargo install --path frep --locked
Read Entire Article