Skip to content

Ability to exclude certain files/folders from showing #2471

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

Closed
godalming123 opened this issue Apr 18, 2023 · 8 comments
Closed

Ability to exclude certain files/folders from showing #2471

godalming123 opened this issue Apr 18, 2023 · 8 comments
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@godalming123
Copy link

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 showing

Describe 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 a meson.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 hidden

Describe other solutions you've considered

  1. Option to exclude certain files/folders in the init.lua
  2. Option to have another file like .telescopeignore to ignore these files
  3. Option to exclude files/folders listed in the .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

@godalming123 godalming123 added the enhancement Enhancement to performance, inner workings or existent features label Apr 18, 2023
@jamestrew
Copy link
Contributor

You have a couple options to accomplish this.

  1. Use the file_ignore_patterns option in your setup function (:h telescope.defaults.file_ignore_patterns)
  2. You can use .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.

@eli-schwartz
Copy link

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?

@jamestrew
Copy link
Contributor

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.

@eli-schwartz
Copy link

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.

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. BurntSushi/ripgrep#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.

@jamestrew
Copy link
Contributor

I wasn't aware of that flag 👍 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" }
    }
  }
  -- ...
}

@godalming123
Copy link
Author

godalming123 commented Apr 19, 2023

Thank you for all the help, there seem to be 3 main solutions:

  1. Using telescope's file ignore patterns
  2. Using .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)
  3. Setting the find_files picker to always use the .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

@jamestrew
Copy link
Contributor

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" }
    }
  }
  -- ...
}

@victor-0x29a
Copy link

Working, thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

No branches or pull requests

4 participants