You are not logged in.

#1 2018-10-16 14:12:52

dmerej
Member
From: Paris
Registered: 2016-04-09
Posts: 71
Website

ruplacer: find and replace text in source files

Screenshot

ruplacer.png

Project info

https://github.com/supertanker/ruplacer/

Ruplacer is a command-line tool to find and replace text in source files.

Features:

  • Honor .gitignore

  • Ignore binary files

  • Fast

  • Can replace patterned captured as a grouped regex

  • Dry run by default, use --go to write changes to disk

  • --subvert mode to perform case conversion

Subvert mode takes care of snake_case versus CamelCase:

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

Ruplacer is available in the AUR.

If you find it useful, have some questions, or any kind of feedback, please let me know smile

P.S: You can also find details of how ruplacer works and a little bit about its history on my blog

Last edited by dmerej (2018-10-16 16:16:35)


Responsible Coder, Scrum Master, Buildfarm Guru, Python3 Fan
twitter: @d_merej mastodon:@dmerej@mamot.fr

Offline

#2 2018-10-16 14:30:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 20,424
Website

Re: ruplacer: find and replace text in source files

How is this different from just using sed?  E.g.,

# Preview:
sed -n '/old/{s/^/-- /p;s/^--/++/;s/old/new/gp;}' *
# Do it:
sed -i 's/old/new/g' *

Last edited by Trilby (2018-10-16 14:33:37)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-10-16 14:59:10

dmerej
Member
From: Paris
Registered: 2016-04-09
Posts: 71
Website

Re: ruplacer: find and replace text in source files

I knew you would ask tongue

Well, there's the nice color output, the syntax is easier to remember and it's fast and  cross-platform. But yeah, UNIX tools  work great for this kind of task.

I just think that sometimes we can take time to rewrite some of these tools and come up with more ergonomic alternatives smile


Responsible Coder, Scrum Master, Buildfarm Guru, Python3 Fan
twitter: @d_merej mastodon:@dmerej@mamot.fr

Offline

#4 2018-10-16 15:08:59

progandy
Member
Registered: 2012-05-17
Posts: 3,195

Re: ruplacer: find and replace text in source files

You already listed a few differences in your initial post.
* parse .gitignore
* --subvert

Then in your readme you mention it ignores binary files.

It can also follow large directory trees that don't fit in a single command line, but that is really unlikely. My shell allows more than 2 million characters.
This could all be done with find, sed and filter scripts called with -exec, but in the end you just have a shell script instead of a rust binary.

Last edited by progandy (2018-10-16 15:17:07)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Online

#5 2018-10-16 15:23:26

dmerej
Member
From: Paris
Registered: 2016-04-09
Posts: 71
Website

Re: ruplacer: find and replace text in source files

Thanks progandy, I've updated the introduction a little


Responsible Coder, Scrum Master, Buildfarm Guru, Python3 Fan
twitter: @d_merej mastodon:@dmerej@mamot.fr

Offline

Board footer

Powered by FluxBB