-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] how to search by filenames only? #193
Comments
From
|
@BurntSushi this is related to the issue I just raised, #284. The I believe the question here is "How can I search for a pattern in the filename, and return the filenames that include that pattern in the path/filename?" It appears that the -g flag limits my search for text within the file to the filenames matching the -g pattern. Does that explain the nuance? Example: If there is a file relative to my directory, |
I have the following alias to shim this in my ~/.bashrc: alias rgf='rg --files | rg' This allows you to do: $ rgf 2018
lib/lib.es2018.full.d.ts
lib/lib.es2018.promise.d.ts
lib/lib.es2018.intl.d.ts
lib/lib.es2018.regexp.d.ts
lib/lib.es2018.asynciterable.d.ts
lib/lib.es2018.d.ts |
how would you do that without the alias? |
@johnyradio just type the command directly:
A Bash alias just substitutes the command for whatever the contents of the alias is, then continues evaluating as usual. That's all an alias is:
=
|
Many thanks! Super helpful.
|
It is best if we can add an actual flag to do this. |
if you want to do this as a "rgf" style alias, use a function instead: function rgf {
rg --files $2 | rg $1
} |
@hraban Thanks for the tip, I updated the logic a bit for future newcomer. rf() {
if [ -z "$2" ]
then
rg --files | rg "$1"
else
rg --files "$2" | rg "$1"
fi
} |
What you suggested searches in the entire path and not just in the filename (what the OP had asked)! |
To search Python in filenames:
Note: Use above in Linux and Mac (for windows replace [^/] with [^]): |
I still hope to see native support for it. There is a huge UX benefit on having it as a default feature and the number of user upthumbs explains it. |
Use |
Thanks, very useful. What does the | mean? Also, this finds filenames that do not match the query because the files contents contain the query. I am only interested in the filename. |
@AtomicNess123 The |
Mmm... I have to digest that. Could you give a more illustrative example? No rush, though... |
At no point are the contents of any files searched in the above example. |
Thanks. What is the difference then between |
The former will print all paths in the current tree that contain 2018. The latter will only print paths containing 2018 where all of its parent directories also contain 2018. The |
Thanks, very insightful! |
Actually, it won't work like that in my case: rg --files -g '*helm*'
xxx-helm-xxx.el
helm/xxx-helm-xxx.el
helm/sub2/xxx-helm-xxx.el
helm/sub2/xxxhelmxxx.el
helm/xxxhelmxxx.el
a/xxx-helm-xxx.el
a/sub2/xxx-helm-xxx.el
a/sub2/xxxhelmxxx.el
a/xxxhelmxxx.el
xxxhelmxxx.el
rg --files | rg helm
xxx-helm-xxx.el
helm/xxx-helm-xxx.el
helm/sub2/xxx-helm-xxx.el
helm/sub2/xxxhelmxxx.el
helm/xxxhelmxxx.el
a/xxx-helm-xxx.el
a/sub2/xxx-helm-xxx.el
a/sub2/xxxhelmxxx.el
a/xxxhelmxxx.el
xxxhelmxxx.el As you can see, the -g flag makes no difference. |
Probably referencing https://github.com/sharkdp/fd. TIL. |
Any way to search for all file nams with a given pattern without having to specify a search pattern? 〉rg -g *.json
ripgrep requires at least one pattern to execute a search |
Yes. Use the |
--files
will list all files which respect ignore files. Is there a flag to list filenames which match the given filename pattern?The text was updated successfully, but these errors were encountered: