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.

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