Code Monkey home page Code Monkey logo

ruplacer's Introduction

Ruplacer

Build

Find and replace text in source files.

ruplacer screenshot

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 assests of the latest release.

  • ruplacer can also be installed from homebrew:

$ brew install supertanker/homebrew-repo/ruplacer

Basic usage

ruplacer pattern replacement [path]

If 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:

$ replacer 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

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

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 captures in pattern in replacement.

For instance, to replace dates looking like MM/DD/YYYY to YYYY-MM-DD, you would use:

$ ruplacer '(\d{2})/(\d{2})/(\d{4})' '$3-$1-$2'

Customizing the replacement algorithm

  • Use --no-regex to prevent ruplacer from interpreting the pattern as a regex.
  • Use --subvert to perform replacements across a variety of case styles:
$ ruplacer --subvert foo_bar spam_eggs
Patching src/foo.txt
-- foo_bar, FooBar, and FOO_BAR!
++ spam_eggs, SpamEggs, and SPAM_EGGS!

ruplacer's People

Contributors

dmerejkowsky avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.