Skip to content
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

Support some ripgrep options e.g. (-t and -g) via the searchbox #770

Closed
davidscotson opened this issue Apr 18, 2021 · 4 comments
Closed
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@davidscotson
Copy link

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

I've previously used ripgrep on the command line to "explore" a filebase i.e. get a list of filenames that feature a string, with the rest of the context from the matching line, not particularly looking for a specific instance, but to see how it's been used and would like to transition to doing the same task with telescope.

When using it on the command line, I will often know some aspect of the file context I am searching for and can immediately narrow down the result via command flags e.g. using one of the ripgrep --type filters to limit the filetypes, or the -g to glob match the filepath/name so that almost all results returned are relevant. I would like some version of that workflow to work from within telescope too. It probably doesn't matter as much when you're aiming for one particular file to open, as you can just keep narrowing down by typing further. But I'd like to get an overview of all the matching files/lines and so the extra filtering should stop my result list being polluted with irrelevant answers, so I can see more of the ones I want in the list, and as a side-benefit should help with the speed of searching.

Describe the solution you'd like
I'm not 100% settled on how this would work best in the interface. In particular it might be nice if this was a generic Telescope pattern that could be used for other tools that might expose options to limit the results beyond text matching. I'll list some alternatives below, but probably the one that most immediately appeals to me is:

I want to open a ripgrep searchbox in telescope, and if i type anything that starts with a - then it will interpret that as a ripgrep command line option, rather than a fuzzy search and pass it through to ripgrep when it starts the search on the first non-option thing I type. eg. "-thtml -tjs doc" in the search box would not ask ripgrep to start searching until i started typing the d in doc and it would pass everything before that as options directly to the rg binary via the command line. That would then limit results to .htm, .html (via the html type) and .js via the js type (in my particular setup it would also skip specifically named minified js files I specify in my .rgignore).

Describe alternatives you've considered

A small wrapper around the current live grep feature could accept the command line switches on the neovim command line, before opening Telescope, I'm going to try to cobble this together for my own use as this seems doable with the current API though my unfamiliarity with lua means my first attempt doesn't seem to work with more than one command flag at a time and I'm not sure why (I would have thought it's just getting flattened to a string, but presumably not if one switch option alone works and two together doesn't):

 nnoremap <leader>ps :lua args = {'rg','--color=never','--no-heading','--with-filename','--line-number','--column','--smart-case'} table.insert(args, vim.fn.input('rg > ')) require('telescope.builtin').live_grep( { vimgrep_arguments = args} )<CR>

https://github.com/nvim-telescope/telescope-fzf-writer.nvim has a feature they call staged grep, where the initial parts of the search are exact searched in rg, and anything you place after a pipe | is used to fuzzy search what comes back which is roughly in the same spirit I think.

FZF has a search syntax, which lets you specify some similar things as part of the search via some special characters, e.g the example in their docs is ^music .mp3$ sbtrkt !fire

I noticed another recent feature request that wanted to be able to restrict the git ls-files to only files that have changes, which is a similar use case, as there is a command line option for that I think.

@davidscotson davidscotson added the enhancement Enhancement to performance, inner workings or existent features label Apr 18, 2021
@elianiva
Copy link
Member

see #670

@davidscotson
Copy link
Author

#670 seems like exactly what I'm looking for so I'm going to close this as a dupe and follow that ticket instead, as it's already way beyond the idea stage.

@RyanzpLee
Copy link

@davidscotson did you manage to get the -t and -g options to work in the end? I've tried using live_grep_raw with the -g argument but my results turn up with nothing

@davidscotson
Copy link
Author

@RyanzpLee , I now use https://github.com/nvim-telescope/telescope-rg.nvim which I found via the linked #670 ticket.

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

3 participants