Closed godalming123 closed 1 year ago
You have a couple options to accomplish this.
file_ignore_patterns
option in your setup
function (:h telescope.defaults.file_ignore_patterns
).gitignore
or .ignore
files in the directory. :Telescope find_files
respects .gitignore
& .ignore
by default. No you need to use :Telescope git_files
. I think you still need to be in a git repo for .gitignore
to work with find_files
, but you can use .ignore
instead if you're not in a git repo. meson setup build/
will already create a .gitignore file to ignore ALL generated files, regardless of whether you are in a git repo. If this project is ignoring those .gitignore files for arbitrary reasons like "you still need to be in a git repo", then why?
arbitrary reasons
I wouldn't call it arbitrary...
The find_files
picker will use rg
or fd
(if available and necessary for respecting .gitignore
and .ignore
). For both, they will only respect .gitignore
if the cwd is a git repo. I think it makes perfect sense for .gitignore
to not carry any meaning outside of a git repository. I don't think telescope will/should overwrite that behavior.
If you want to use .gitignore
, make the cwd a git repo. Alternatively, you can simply rename the generated .gitignore
file to .ignore
. Alternatively, you can use file_ignore_patterns
.
The
find_files
picker will userg
orfd
(if available and necessary for respecting.gitignore
and.ignore
). For both, they will only respect.gitignore
if the cwd is a git repo. I think it makes perfect sense for.gitignore
to not carry any meaning outside of a git repository. I don't think telescope will/should overwrite that behavior.
rg has a flag for this, --no-require-git
. Overwriting that behavior is lightweight enough that it's a policy choice, not a technical choice: do you agree with rg's reasoning for disabling this by default, or not? Hmm, maybe this can be configured by the user?
...
For context, the ripgrep decision is e.g. https://github.com/BurntSushi/ripgrep/issues/1229 and the underlying reason for ripgrep doing this is, IMO, a ripgrep bug: ripgrep will look up your git config --get core.excludesFile
and apply this as well as the .gitignore file, core.excludesFile should, reasonably, not be applying to things that are not git repos, the "solution" inside ripgrep was to disable both outside of git repos instead of just the former.
I wasn't aware of that flag :+1: I do agree with burntsushi although maybe not to the same degree.
The UX of a flag like this is absolutely atrocious. It's so obscure that it's really not worth explicitly calling it out anywhere. Moreover, the error cases that occur when this flag isn't used (but its behavior is desirable) will not be intuitive, do not seem easily detectable and will not guide users to this flag. Nevertheless, the motivation for this is just barely strong enough for me to begrudgingly accept this.
With this flag you can also pass a find_command
option to find_files
, or set it as a picker option in the setup
function.
require'telescope'.setup{
defaults = {
-- ...
},
pickers = {
find_files = {
find_command = { "rg", "--files", "--color", "never", "--no-require-git" }
}
}
-- ...
}
Thank you for all the help, there seem to be 3 main solutions:
.gitignore
and .ignore
to stop ripgrep from searching directorys (the reason that this did not work for me is because I did not have ripgrep installed).gitignore
with rpigrep this elaborates upon the prior solution by not requiring a git repo to ignore files from .gitignore
I think that the option (and possibly default) to use the --no-require-git
arg with ripgrep (the 3rd solution) would be a nice edition especially since telescope already doesn't allow you (as far as I know) to show files ignored by ripgrep when you are in a git repo
find_files
with fd
or rg
will respect ignore by default.
My recommendation would be to install either one of them (or both, they're nice to have) and then pass the --no-require-git
flag to the find_command
option like I've shown above if you would like that to be the default behavior for yourself.
With fd
you can do instead:
require'telescope'.setup{
defaults = {
-- ...
},
pickers = {
find_files = {
find_command = { "fd", "--type", "f", "--color", "never", "--no-require-git" }
}
}
-- ...
}
Working, thx!
Is your feature request related to a problem? Please describe. I'm always frustrated when I try to find a file in my small project but am sifting though loads of files that were generated with
meson build
this may be solvable if I search git files instead of filesystem files but I do not think a should have to create a local git repo just to avoid all of my meson build files from showingDescribe the solution you'd like A predefined list of files/folders that should be ignored and possibly with certain conditions like the
build/
folder should only be ignored if the folder it is in has ameson.build
but with the option for users to override these settings either in their neovim configs or a local file in the directory where they would like a file to be shown/hidden you could also add a custom command to show just the files telescope has hiddenDescribe other solutions you've considered
init.lua
.telescopeignore
to ignore these files.gitignore
I think all of these solutions have their cons, excluding files in the
init.lua
could clutter user configs with files that should be in their personal projects and is another thing users would have to configure despite - in my opinion - hiding binary files/buildfiles should be a saner default, adding a .telescopeignore file is another file to have to add and again users must configure it themselves, and as for using the.gitignore
file this seems silly after I said that the reason I did not want to use git_files was because not all my folders are git repos