Add multigrep from TJ's video
This commit is contained in:
parent
ffc12963c4
commit
58f645ee50
57
nvim/lua/opdavies/telescope/multigrep.lua
Normal file
57
nvim/lua/opdavies/telescope/multigrep.lua
Normal file
|
@ -0,0 +1,57 @@
|
|||
local conf = require("telescope.config").values
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local pickers = require "telescope.pickers"
|
||||
|
||||
local M = {}
|
||||
|
||||
local live_multigrep = function(opts)
|
||||
opts = opts or {}
|
||||
opts.cwd = opts.cwd or vim.uv.cwd()
|
||||
|
||||
local finder = finders.new_async_job {
|
||||
command_generator = function(prompt)
|
||||
if not prompt or prompt == "" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local pieces = vim.split(prompt, " ")
|
||||
local args = { "rg" }
|
||||
|
||||
if pieces[1] then
|
||||
table.insert(args, "-e")
|
||||
table.insert(args, pieces[1])
|
||||
end
|
||||
|
||||
if pieces[2] then
|
||||
table.insert(args, "-g")
|
||||
table.insert(args, pieces[2])
|
||||
end
|
||||
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
return vim.tbl_flatten {
|
||||
args,
|
||||
{ "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case" },
|
||||
}
|
||||
end,
|
||||
|
||||
cwd = opts.cwd,
|
||||
entry_maker = make_entry.gen_from_vimgrep(opts),
|
||||
}
|
||||
|
||||
pickers
|
||||
.new(opts, {
|
||||
debounce = 100,
|
||||
finder = finder,
|
||||
previewer = conf.grep_previewer(opts),
|
||||
prompt_title = "Multi Grep",
|
||||
sorter = require("telescope.sorters").empty(),
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
M.setup = function()
|
||||
vim.keymap.set("n", "<leader>fg", live_multigrep)
|
||||
end
|
||||
|
||||
return M
|
|
@ -50,7 +50,6 @@ end
|
|||
vim.keymap.set("n", "<space>/", builtin.current_buffer_fuzzy_find)
|
||||
vim.keymap.set("n", "<space>fb", builtin.buffers)
|
||||
vim.keymap.set("n", "<space>fd", builtin.find_files)
|
||||
vim.keymap.set("n", "<space>fg", builtin.live_grep)
|
||||
vim.keymap.set("n", "<space>fh", builtin.help_tags)
|
||||
vim.keymap.set("n", "<space>fi", M.search_all_files)
|
||||
vim.keymap.set("n", "<space>fk", builtin.keymaps)
|
||||
|
@ -65,3 +64,5 @@ vim.keymap.set("n", "<space>dgb", M.grep_bluecheese)
|
|||
vim.keymap.set("n", "<space>dgd", M.grep_drupalorg_theme)
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<space>gw", builtin.grep_string)
|
||||
|
||||
require("opdavies.telescope.multigrep").setup {}
|
||||
|
|
Loading…
Reference in a new issue