mirror of
https://github.com/LazyVim/starter.git
synced 2026-07-22 04:21:03 +00:00
New live grep
This commit is contained in:
parent
3b72052a1a
commit
f35d669229
2 changed files with 59 additions and 19 deletions
56
lua/mj/telescope/grep_with_args.lua
Normal file
56
lua/mj/telescope/grep_with_args.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
local pickers = require("telescope.pickers")
|
||||
local finders = require("telescope.finders")
|
||||
local make_entry = require("telescope.make_entry")
|
||||
local config = require("telescope.config").values
|
||||
|
||||
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, " ") -- double space
|
||||
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,
|
||||
entry_maker = make_entry.gen_from_vimgrep(opts),
|
||||
cwd = opts.cwd,
|
||||
})
|
||||
|
||||
pickers
|
||||
.new(opts, {
|
||||
debounce = 100,
|
||||
prompt_title = "Multi Grep",
|
||||
finder = finder,
|
||||
previewer = config.grep_previewer(opts),
|
||||
sorter = require("telescope.sorters").empty(),
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
M.setup = function()
|
||||
live_multigrep()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -10,26 +10,10 @@ return {
|
|||
cwd = project_root, -- Force project root
|
||||
})
|
||||
end, { desc = "Find Files (Project Root)" })
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-telescope/telescope-live-grep-args.nvim",
|
||||
dependencies = { "nvim-telescope/telescope.nvim" },
|
||||
config = function()
|
||||
require("telescope").load_extension("live_grep_args")
|
||||
|
||||
vim.keymap.set("n", "<leader>sg", function()
|
||||
require("telescope").extensions.live_grep_args.live_grep_args()
|
||||
end, { desc = "Live Grep with Args" })
|
||||
vim.keymap.set("n", "<Space>sg", function()
|
||||
require("mj.telescope.grep_with_args").setup()
|
||||
end, { desc = "Custom Live Grep With args" })
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
-- opts = function(_, opts)
|
||||
-- vim.keymap.set("n", "<Space><Space>", function()
|
||||
-- local project_root = require("project_nvim.project").get_project_root() or vim.fn.getcwd()
|
||||
-- require("telescope.builtin").find_files({
|
||||
-- cwd = project_root, -- Force project root
|
||||
-- })
|
||||
-- end, { desc = "Find Files (Project Root)" })
|
||||
-- end,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue