Skip to content

Commit caee132

Browse files
committed
feat(grep): fn_transform_cmd with ctrl-g toggle (#1927)
1 parent d5fd2a4 commit caee132

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lua/fzf-lua/make_entry.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,18 @@ M.preprocess = function(opts)
202202
end
203203
end
204204

205+
-- For custom command transformations (#1927)
206+
opts.fn_transform_cmd =
207+
load_config_section("__resume_data.opts.fn_transform_cmd", "function", true)
208+
205209
-- did the caller request rg with glob support?
206210
-- manipulation needs to be done before the argv replacement
207-
if opts.rg_glob then
211+
if opts.fn_transform_cmd then
212+
local query = argv(nil, opts.debug)
213+
local new_cmd, new_query = opts.fn_transform_cmd(query, opts.cmd:gsub(argvz, ""), opts)
214+
opts.cmd = new_cmd or opts.cmd
215+
opts.cmd = opts.cmd:gsub(argvz, libuv.shellescape(new_query or query))
216+
elseif opts.rg_glob then
208217
local query = argv(nil, opts.debug)
209218
local search_query, glob_args = M.glob_parse(query, opts)
210219
if glob_args then
@@ -219,14 +228,6 @@ M.preprocess = function(opts)
219228
end
220229
end
221230

222-
-- For custom command transformations (#1927)
223-
opts.fn_transform_cmd =
224-
load_config_section("__resume_data.opts.fn_transform_cmd", "function", true)
225-
if opts.fn_transform_cmd then
226-
local query = argv(nil, opts.debug)
227-
opts.cmd = opts.fn_transform_cmd(query, opts.cmd:gsub("{argv.*}", "") ,opts)
228-
end
229-
230231
-- nifty hack to avoid having to double escape quotations
231232
-- see my comment inside 'live_grep' initial_command code
232233
if opts.argv_expr then

lua/fzf-lua/providers/grep.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ local get_grep_cmd = function(opts, search_query, no_esc)
5454
opts.rg_glob = false
5555
end
5656

57-
if opts.rg_glob then
57+
if opts.fn_transform_cmd then
58+
local new_cmd, new_query = opts.fn_transform_cmd(search_query, opts.cmd, opts)
59+
if new_cmd then
60+
opts.no_esc = true
61+
opts.search = new_query
62+
return new_cmd
63+
end
64+
elseif opts.rg_glob then
5865
local new_query, glob_args = make_entry.glob_parse(search_query, opts)
5966
if glob_args then
6067
-- since the search string mixes both the query and

0 commit comments

Comments
 (0)