ProductPromotion
Logo

Rust

made by https://0x3d.site

GitHub - your-tools/ruplacer: Find and replace text in source files
Find and replace text in source files. Contribute to your-tools/ruplacer development by creating an account on GitHub.
Visit Site

GitHub - your-tools/ruplacer: Find and replace text in source files

GitHub - your-tools/ruplacer: Find and replace text in source files

crates.io image

Ruplacer

Find and replace text in source files:

$ ruplacer old new src/
Patching src/a_dir/sub/foo.txt
-- old is everywhere, old is old
++ new is everywhere, new is new

Patching src/top.txt
-- old is nice
++ new is nice

Would perform 2 replacements on 2 matching files.
Re-run ruplacer with --go to write these changes to disk

Note

This project was originally hosted on the TankerHQ GitHub organization, which was my employer from 2016 to 2021. They kindly agreed to give me back ownership of this project. Thanks!

Installing with cargo

Install rust and cargo, for example with rustup.

Then run:

cargo install ruplacer

Alternative installation methods

  • Pre-compiled binaries for Linux, macOS, and Windows are available as assets of the latest release.

  • ruplacer can also be installed from homebrew:

brew install TankerHQ/homebrew-repo/ruplacer

Basic usage

ruplacer pattern replacement [path]

If the path is not given, it defaults to the current working directory.

Ruplacer will then walk through every file in <path> while honoring .gitignore files found on the way.

Binary files and text files containing non-UTF8 characters will be skipped. Then for every remaining file, it will read the contents, replace all lines matching the pattern by the replacement, and print the difference.

If you are OK with the replacements, re-run ruplacer with the --go option to actually write the changes to disk.

Regex

By default, pattern will be compiled into a Rust regex.

Note that it's slightly different from Perl-style regular expressions. Also, you must use $1, $2 to reference groups captured from pattern inside replacement.

For instance, this replaces 'last, first' by 'first last':

ruplacer '(\w+), (\w+)' '$2 $1'

(note the use of single quotes to avoid any processing by the shell)

If you don't want the pattern to be used as a regex, use the --no-regex command line flag.

This makes it possible to look for special characters without escaping them:

# This is a regex that matches the letter a
# or the letter o
$ ruplacer '(a|o)' u
- tata toto
+ tutu tutu
- (a|o)
+ (u|u)

# This is the literal string: '(a|o)'
$ ruplacer --no-regex '(a|o)' u
# or
$ ruplacer '\(a\|o|)' u
- (a|o)
+ u

Preserving case while replacing

Ruplacer has a --preserve-case option which works across a variety of case styles (lower case, snake case, and so on):

$ ruplacer --preserve-case foo_bar spam_eggs
Patching src/foo.txt
-- foo_bar, FooBar, and FOO_BAR!
++ spam_eggs, SpamEggs, and SPAM_EGGS!

Filter files by type or glob patterns

Inspired by ripgrep, you can also select or ignore certain "file types" or glob patterns:

# Select only C++ files
$ ruplacer old new --type cpp
# Select only *.foo files
$ ruplacer old new --type *.foo
# Select only files that match foo*bar.c
$ ruplacer old new --type foo*bar.c

# Ignore all js files
$ ruplacer old new --type-not js
# Ignore all *.bar files
$ ruplacer old new --type-not *.bar
# Ignore all files that match foo*bar.c
$ ruplacer old new --type-not foo*bar.c

Each "file type" is just a list of glob pattern. For instance: the cpp file type matches *.C, *.H, *.cc, *.cpp and so on ...

You can see the whole list by using ruplacer --type-list.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory