-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
I would like to have the ability to provide a custom prompt_parser
to further customize this plugin. It'll be extra nice if the parser can return some extra arguments to be passed on to vimgrep_args
Example Use case:
I want to just type what i want into the field and not think about quotes and globs and break the flow when I'm in the middle of debugging something.
Here's my test implementation of prompt_parser
. Probably buggy and misses some corner cases but I used it on a whole day of work and it seemed fine.
I'll add the ability to escape /
and starting -
in the future.
Maybe we can have this kind of 'quoteless mode' as a feature on the plugin.
-- somewhere_in_my_config.lua
-- **
opts.prompt_parser = require('plugins.my-custom-prompt-parser')
require('telescope').extensions.live_grep_args.live_grep_args(opts)
-- plugins/my-custom-prompt-parser.lua
local M = {}
M.parse = function(prompt, _)
local parts = ''
local args = {}
local path = nil
path_index = prompt:find("/")
if path_index then
path_start_index = prompt:sub(0, path_index):find('%s[%S]*$')
path_end_index = (prompt:find('%s', path_start_index+1) or 0)-1
path = prompt:sub(path_start_index+1, path_end_index)
if path:sub(-1) == '*' then path = path .. '/' end
if path:sub(1, 1) == '/' then path = path:sub(2, -1) end
new_prompt = prompt:sub(0, path_start_index-1)
if path_end_index ~= -1 then new_prompt = new_prompt .. prompt:sub(path_end_index+1, -1) end
prompt = new_prompt
table.insert(args, '--glob='.. path .. '**')
end
arg_index = prompt:find("%s%-")
if arg_index then
table.insert(args, prompt:sub(arg_index+1, -1))
parts = prompt:sub(1, arg_index-1)
else
parts = prompt
end
return { args }, { parts }
end
return M
Demo:
demo.mp4
Example implementation:
I'm not sure if it's a good idea to do it like this, but just wanted to test the functionality, here's the PR: #52
daniel-zaretsky1
Metadata
Metadata
Assignees
Labels
No labels