Recursive search and replace CLI application.
git clone https://github.com/gfannes/molybdenum
cargo install --path molybdenum
mo -h
should print its help and versionPowerful search can be found without problems, eg, grep, ack, ag, ripgrep or broot.
Tools for replacing recursively in a folder are more difficult to find, although some exist: fart-it. Typically, people use a combination of searching, xargs and a replacement tool like sed or rpl.
I use code searching a lot to investigate a large source code base before attempting a replace. Even with 100k files, search is fast and fairly easy. Recursively replacing text is much more dangerous, especially if it requires the combination of several less frequently used tools; it's difficult to remember a search-xargs-replace
combination if not used on a daily basis. On top of this, the search
tool used to filter the set of files and perform a dry-run, is not per-se using the same search query as the replace
tool. After all, these are different tools. It would be better if a single tool could be used for every-day searching and replacing. This is exactly what The Molybdenum Replacer intends to achieve.
In addition, I find it difficult to use ag
and rg
to filter against the file path and search for content in the remaining files; the -g
option for ag
and rg
is confusing in my opinion. As such, I would expect ag -g /auro/ -w test
to search for the word test
in all files that have /auro/
in their path, but that is not what actually happens. It filters with /auro/
and test
against the filename (or something that looks like it).
The real reason, of course, is that I had some free time and was looking for a nice project/excuse to learn rust.
Following features are implemented and usable in the current version:
Following features might be added sooner or later:
mo
is currently single-threaded. To achieve ripgrep-like performance, all CPU's are probably required.-l
is used to only output filenames, mo
can stop searching after the first match.molybdenum
, and it is very hard to type. mo
is better, but difficult to search on the internet..gitignore
files0x0a
.``
Scenario: count all files
Running
mo -l -u -U -a | wc`
Elapsed time: 0:00.29
Output: 184675 187146 16959297
Running rg --files -uu -a | wc
Elapsed time: 0:00.15
Output: 184675 187146 16589947
Running ag -l -uu -a | wc
Elapsed time: 0:00.66
Output: 184675 187146 16589947
```
``
Scenario: search for word
testin .cpp files in subfolder
corewhere path contains /auro/
Running
mo -C core -e cpp -f /auro/ -w -p test -l | wc`
Elapsed time: 0:00.03
Output: 165 165 9008
Running rg -t cpp --files core | rg /auro/ | rg '.cpp$' | tr '\n' '\0' | xargs -0 rg -i -w test -l | wc
Elapsed time: 0:00.01
Output: 165 165 9008
Running ag --cpp -l . core | ag /auro/ | ag '.cpp$' | tr '\n' '\0' | xargs -0 ag -w test -l | wc
Elapsed time: 0:00.05
Output: 165 165 9008
```
I don't know how I can accomplish this scenario with ag
and rg
in a single command without relying on xargs
and tr
.