EDIT
A very basic code example to achieve fuzzy search using a single grep would be:
(defun custom-counsel-function (str)
(or
(ivy-more-chars)
(progn
(let ((str (split-string str)))
(counsel--async-command
(format "rg --max-columns 240 --with-filename --no-heading --line-number --color never '%s' | grep %s"
(car str) (cadr str))))
'("" "working..."))))
;;;###autoload
(defun custom-counsel (&optional initial-input)
"Call the \"locate\" shell command.
INITIAL-INPUT can be given as the initial minibuffer input."
(interactive)
(let ((default-directory (read-directory-name "Start search from directory: ")))
(ivy-read "Ripgrep: " #'custom-counsel-function
:initial-input initial-input
:dynamic-collection t
:history 'counsel-locate-history
:action (lambda (file)
(with-ivy-window
(when file
(find-file file))))
:unwind #'counsel-delete-process
:caller 'counsel-locate)))
The rg
and grep
patterns can be entered by separating them using a single space. For sure there are nicer ways to achieve this, but it takes some more time to inspect the Ivy (or any other completion framework) API.
END EDIT
From M-x man
rg
we find that this can be achieved using the -g
flag. Now neither projectile-ripgrep
nor the ripgrep-regexp
command allow you to pass arguments to rg
when called interactively (you can look at their definitions to see how they work).
However, counsel-rg
of the swiper/Ivy package does allow for passing arguments, and an example of how to use it is given in its docstring (and probably there exist helm and possibly consult alternatives for this also).
For filtering on directory paths, be sure to read well the documentation after -g
in rg
's man
-page. For example, to filter for files that are located in some-path dir-example/file.ext
relative from your initial search directory, you could search for the following:
ripgrep-pattern -- -g dir*/*
ripgrep
let you pipe directly, the wayM-x grep
does?C-u
, where you can define a directory/pattern you want to search in, but there is not way to do fuzzy search in file content and file path relative to project root at the same time Example: I want to search word "text" in all project files containing "test_dir" in any place within file path relative to project's root