Skip to content

Commit cadb6c4

Browse files
committed
feat(grug-far-nvim): add oil.nvim integration
1 parent 481c238 commit cadb6c4

File tree

1 file changed

+27
-9
lines changed
  • lua/astrocommunity/search/grug-far-nvim

1 file changed

+27
-9
lines changed

lua/astrocommunity/search/grug-far-nvim/init.lua

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
local function grug_far_explorer(dir)
2+
local grug_far, prefills = require "grug-far", { paths = dir }
3+
if not grug_far.has_instance "explorer" then
4+
grug_far.open {
5+
instanceName = "explorer",
6+
prefills = prefills,
7+
staticTitle = "Find and Replace from Explorer",
8+
}
9+
else
10+
grug_far.open_instance "explorer"
11+
grug_far.update_instance_prefills("explorer", prefills, false)
12+
end
13+
end
14+
115
---@type LazySpec
216
return {
317
"MagicDuck/grug-far.nvim",
@@ -88,15 +102,7 @@ return {
88102
commands = {
89103
grug_far_replace = function(state)
90104
local node = state.tree:get_node()
91-
local prefills = { paths = node:get_id() }
92-
if node.type ~= "directory" then prefills.paths = vim.fn.fnamemodify(prefills.paths, ":h") end
93-
local grug_far = require "grug-far"
94-
if not grug_far.has_instance "tree" then
95-
grug_far.open { instanceName = "tree", prefills = prefills, staticTitle = "Find and Replace from Tree" }
96-
else
97-
grug_far.open_instance "tree"
98-
grug_far.update_instance_prefills("tree", prefills, false)
99-
end
105+
grug_far_explorer(node.type == "directory" and node:get_id() or vim.fn.fnamemodify(node:get_id(), ":h"))
100106
end,
101107
},
102108
window = {
@@ -106,6 +112,18 @@ return {
106112
},
107113
},
108114
},
115+
{
116+
"stevearc/oil.nvim",
117+
optional = true,
118+
opts = {
119+
keymaps = {
120+
gs = {
121+
desc = "Search/Replace in directory",
122+
callback = function() grug_far_explorer(require("oil").get_current_dir()) end,
123+
},
124+
},
125+
},
126+
},
109127
},
110128
---@param opts GrugFarOptionsOverride
111129
opts = function(_, opts)

0 commit comments

Comments
 (0)