nvim-telescope / telescope-live-grep-args.nvim

Live grep with args
726 stars 40 forks source link

Add Support for Pattern Searching Against Only File Names #87

Open joeyagreco opened 2 months ago

joeyagreco commented 2 months ago

Is your feature request related to a problem? Please describe.

I love using this plugin like so:

keymap.set(
    "n",
    "<leader>fs",
    telescope.extensions.live_grep_args.live_grep_args,
    helpers.combine_tables(default_options, { desc = "search for words" })
)

This is great for searching for text inside files.

I would like something like this but for searching for files.

Currently I use this from telescope

keymap.set("n", "<leader>ff", telescope_builtin.find_files, helpers.combine_tables(default_options, { desc = "find files" }))

Which does not support ripgrep.

The feature I'm describing was best described here and the solution that I believe makes the most sense is here in the same thread.

Simply adding --files to a pattern does not give the required behavior.

Per rg -h

--files Print each file that would be searched.

The desired behavior is to Print each file where that file name matches the pattern given.


Describe the solution you'd like

Allow for prefixing a search with rg --files | rg so that the search returns filenames that match the pattern given, not filenames that contain matches for the pattern.

This could be in the form of a helper function similar to quote_prompt in telescope-live-grep-args.actions

Which would allow users to configure something like this

local live_grep_args_shortcuts = require("telescope-live-grep-args.shortcuts")
keymap.set("n", "<leader>ff", live_grep_args_shortcuts.grep_for_files)

Ideally, this would work just like telescope.extensions.live_grep_args.live_grep_args but with the above mentioned functionality of only applying the pattern search on file names and only returning file names.


Describe alternatives you've considered I tried essentially recreating this plugin but for files using Telescope functions.

This was kind of a hassle but I was able to get it somewhat working.

Additional context Thread referenced earlier: https://github.com/BurntSushi/ripgrep/issues/193

Thanks!