6 releases

0.0.7 Jan 1, 2024
0.0.6 Oct 24, 2023
0.0.4 Jul 4, 2023
0.0.2 Jun 25, 2023

#750 in Text processing

Download history 1/week @ 2024-07-28 8/week @ 2024-09-22 7/week @ 2024-09-29

60 downloads per month

MIT license

6.5MB
824 lines

Rep

rep is a command-line utility that takes grep-formatted lines via standard input, and performs a find-and-replace on them. By default, it outputs a diff-preview of the changes to standard output, and with a flag it can write the changes to the files in place.

Find & replace with rep

Example

Output a diff to standard output replacing foo with bar:

grep -n foo *` | rep foo bar

Add the -w flag to write the changes to the files in place:

grep -n foo *` | rep foo bar -w

The -n (--line-number) option is required so that grep outputs the line number for each match.

Installation

rep is available via cargo:

cargo install rep-grep

Configuration

The default pager is less, the REP_PAGER environment variable can be used to override the pager (e.g., export REP_PAGER=delta in Bash).

Help

rep -h (or rep --help, --help provides slightly longer explanations of some options) will list help for all the command-line flags.

Acknowledgements

  • rep was inspired by wgrep for Emacs, which allows editing grep results in an Emacs buffer and then writing those changes to the source files.
  • Much of the functionality, and the overall structure of the source code, was borrowed sd. rep began as a fork of sd.
  • The code for specifying a custom pager for rep was borrowed from delta`.

Dependencies

~12–23MB
~351K SLoC