MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
720 stars 20 forks source link

Add recipe for searching/replacing in mini.files #257

Closed Frestein closed 1 day ago

Frestein commented 2 days ago

I would like to propose adding an integration recipe for mini.files to the grug-far.nvim README. This integration allows users to easily search within the current working directory using grug-far when navigating files with mini.files.

local files_grug_far_cwd = function(path)
  -- Works only if cursor is on the valid file system entry
  local cur_entry_path = MiniFiles.get_fs_entry().path
  local prefills = { paths = vim.fs.dirname(cur_entry_path) }
  local grug_far = require "grug-far"

  if not grug_far.has_instance "explorer" then
    grug_far.open {
      name = "explorer",
      prefills = prefills,
      staticTitle = "Find and Replace from Explorer",
    }
  else
    grug_far.open_instance "explorer"
    -- updating the prefills without crealing the search and other fields
    grug_far.update_instance_prefills("explorer", prefills, false)
  end
end

autocmd("User", {
  pattern = "MiniFilesBufferCreate",
  callback = function(args)
    map("n", "gs", files_grug_far_cwd, { buffer = args.data.buf_id, desc = "Search cwd" })
  end,
})
MagicDuck commented 1 day ago

@Frestein sure, that would awesome! Please go ahead and create a PR. bonus points if you include a link to a video of it in action 😄