$ fzf-search [PATH...]
Search a source tree recursively with rg
and fzf
.
When you are working in a large repository/working directory, searching for blocks of text in hundreds of files can be difficult. This FZF interface for Ripgrep addresses that by letting you narrow down your search results recursively. A search is restricted to the set of files with matches in the previous step. At any point, you can easily switch between searching file contents or filtering file paths. Here is a mini screencast demonstrating some of these features.
PS: You can access a cheat-sheet by pressing F1 at any point.
- F1 help message
- C-s search source tree recursively
- C-f limit files to search
- RET - open in a pager (
bat
orless
) - M-RET - open in
$EDITOR
- Find files to search in current directory/path(s):
$ fzf-file [PATH...]
- Search the current directory/in paths:
$ fzf-search [PATH...]
More documentation on usage can be found in the manual.
- Ripgrep or
rg
for search fzf
for display & filtering UI- (optional)
bat
for preview. It's acat
clone with syntax highlighting support. If it isn't found in$PATH
,less
is used. man
to see the help message
You need to install the above dependencies using your platform's
package manager. After that you have to make sure the scripts in this
repo are in your $PATH
. There are several ways you could achieve
this:
-
Checkout this repo, and add it to your
$PATH
git checkout https://github.com/suvayu/fzf_search.git export PATH="$PWD/fzf_search:$PATH"
To make this permanent, set this value of
$PATH
in your shell's profile/rc file. For Bash that would be~/.bash_profile
or~/.bashrc
. -
Checkout this repo, and create symlinks to the scripts in a directory that is present in your
$PATH
. Say~/bin
is in your$PATH
.git checkout https://github.com/suvayu/fzf_search.git cd ~/bin ln -s $OLDPWD/fzf_search/fzf-{search,file} .
-
Copy over the scripts (
fzf-{search,file}
) andhelp.1
to a directory in your$PATH
. Note that when copying the files you also need to copy the help file to be able to see the help message. This is because scripts try to find the help file in the same directory.
Out of the above methods, (2) is preferred if you already have a setup
where you have a user directory in your $PATH
, however if that's not
the case, (1) is a somewhat simpler alternative. While (3) works, it
is discouraged as it's difficult to update the scripts.
If you are on NixOS (or use the nix
package manager independently),
the repo includes a flake recipe so that you can run the scripts with:
nix run github:suvayu/fzf_search#fzf-search
or
nix run github:suvayu/fzf_search#fzf-file
If you have followed options (1) or (2) to install the scripts, you
may update by navigating to the git repository, and running git pull
. If you opted for option (3) to install, you need to reinstall.
For some reason ANSI escape codes are not being interpreted by fzf
correctly, that leads to incorrect file names, which breaks the file
preview. You can disable colour as a workaround.
$ NOCOLOR=1 fzf-search [PATH...]
If binary files are showing up in matches, you can ignore them as:
$ NOBINARY=1 fzf-search [PATH...]