>> Become my 1st Sponsor on GitHub <<
(click to expand)
TODO: [ElectricRCAircraftGuy#1]: add gif demo image here
I need some testers on Mac and Windows! If you have those operating systems, please get this script running and document how you did it in a new Issue on this repo. I can then add your instructions to the "Installation" section in this readme, below.
- test on Linux Ubuntu
- test on MacOS
- test on Windows
Both rgr
and rgf
are done and fully implemented and work well.
For now, just see the top of each file for instructions in the comments.
TODO:
- add an installation script named
install.sh
that can be run in one single command, even withOUT downloading the repo manually first! Ex. cmd of what this might look like (see here for a demo of this type of cmd):wget https://github.com/ElectricRCAircraftGuy/ripgrep_replace/blob/main/install.sh -O /tmp/ && /tmp/install.sh
ripgrep_replace, or rgr
, is a light-weight wrapper around ripgrep (rg
), supporting 100% of ripgrep's features + adding -R
to enable on-disk find-and-replace!
Finally, we can use ripgrep, the world's fastest grep (regular expression search) tool to do rapid code refactoring via find-and-replace name changes from the command-line!
The Ripgrep author says here:
I am never going to add this [replace in files] to ripgrep. It isn't happening.
Normally I would lock this issue. But folks are still posting helpful content about other approaches. So I'm going to leave this open, but I'm going to mark comments asking for this to be in ripgrep as off topic.
There is no hope. It will never happen. Final decision.
Ripgrep_replace's primary purpose, therefore, is to add "replace in files" to ripgrep via the -R
option. See rgr -h
for details.
Here's a script worth trying: Ripgrep Fuzzyfinder: rgf.sh
: https://github.com/ElectricRCAircraftGuy/ripgrep_replace/blob/main/rgf.sh.
Installation instructions are in the top of the file.
Just type rgf
once installed, and it allows you to interactively, recursively search the whole repository or directory you are in. It uses rg
(ripgrep) under the hood as the regex search engine to search for any string, and fzf
(fuzzy finder) in this case provides just the interactive interface.
TODO:
- Allow live toggling between
rg
(ripgrep search) andfzf
(fuzzy finder search) to choose your search engine: https://github.com/junegunn/fzf/blob/master/ADVANCED.md#switching-between-ripgrep-mode-and-fzf-mode - Allow
rgf
to search the file names too, which it currently doesn't. As a temporary work-around, you can do this, however, to search file names as well:rg search_string | fzf # with color and line numbers rg --color always -n search_string | fzf --ansi # OR, to fuzzy search **everything**! # NB: this can potentially take a lot of RAM (many gigabytes), because it # loads **all file contents** in this folder and down into RAM, to be # searched. rg --hidden -L '' | fzf # With color and line numbers rg --hidden -L --color always -n '' | fzf --ansi
- Add a preview window to see inside the file live while searching. This requires the
bat
tool. See this example and screenshot, for instance: https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interative-ripgrep-launcher. Be sure to add the installation commands ofbat
to the top ofrgf
once you add this dependency. - Add a feature that keeps the last screen of
fzf
output still on the screen even after killing the program and exiting. This would be like what the-X
does inless -RFX filename
(see here).
To search for files in a directory or repo, do:
find | fzf -m
Then, use the arrow keys to move the selector up and down. Press Tab to toggle a file selection on and off. Press Enter to return from the fzf
program and print out the paths to your files you selected. Open these files manually in whatever editor you see fit.
OR, use my sublf
program (Sublime Text file fuzzy finder) to find, select, and automatically open all selected files in either Sublime Text or the editor of your choice (see below).
Add a ~/.sublf_config.sh
config. file to allow customizing the default options passed to find
inside sublf
. For the most-correct find -not
type syntax to excluded certain files or directories, see my detailed answer here: How do I exclude a directory when using find
?
TODO:
- Allow setting a default editor as well inside the
~/.sublf_config.sh
configuration file. For now, you can simply change thesubl "${files_selected_array[@]}"
command near the bottom of thesublf.sh
script to explicitly use the editor of your choice. Ex: open in vim withvim "${files_selected_array[@]}"
.
TODO: see: ElectricRCAircraftGuy#1 (comment)
- My eRCaGuy_dotfiles repo.
- My eRCaGuy_hello_world repo.