You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. local pickers = require("telescope.pickers")
  2. local finders = require("telescope.finders")
  3. local make_entry = require("telescope.make_entry")
  4. local conf = require("telescope.config").values
  5. local M = {}
  6. M.live_multgrep = function (opts)
  7. opts = opts or {}
  8. opts.cwd = opts.cwd or vim.uv.cwd()
  9. local finder = finders.new_async_job({
  10. command_generator = function (prompt)
  11. if not prompt or prompt == "" then
  12. return nil
  13. end
  14. local pieces = vim.split(prompt, " ")
  15. local args = { "rg" }
  16. if pieces[1] then
  17. table.insert(args, "-e")
  18. table.insert(args, pieces[1])
  19. end
  20. if pieces[2] then
  21. table.insert(args, "-g")
  22. table.insert(args, pieces[2])
  23. end
  24. ---@diagnostic disable-next-line: deprecated
  25. return vim.tbl_flatten({
  26. args,
  27. {
  28. "--color=never",
  29. "--no-heading",
  30. "--with-filename",
  31. "--line-number",
  32. "--column",
  33. "--smart-case",
  34. "--hidden",
  35. }
  36. })
  37. end,
  38. entry_maker = make_entry.gen_from_vimgrep(opts),
  39. cwd = opts.cwd
  40. })
  41. pickers.new(opts, {
  42. debounce = 100,
  43. prompt_title = "Multi Grep",
  44. finder = finder,
  45. previewer = conf.grep_previewer(opts),
  46. sorter = require("telescope.sorters").empty(),
  47. }):find()
  48. end
  49. return M