internal: only replace {argv} when requested by live_grep

main
bhagwan 2 years ago
parent 8ad6e92b9f
commit 58e159c36e

@ -311,6 +311,7 @@ M.mt_cmd_wrapper = function(opts)
local opts_to_str = function(o)
local names = {
"debug",
"argv_expr",
"cmd",
"cwd",
"git_icons",

@ -287,10 +287,13 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
fn_transform = load_fn(fn_transform)
fn_preprocess = load_fn(fn_preprocess)
-- if opts.argv_expr and opts.debug then
-- io.stdout:write("[DEBUG]: "..opts.cmd.."\n")
-- end
-- run the preprocessing fn
if fn_preprocess then fn_preprocess(opts) end
-- for i=0,8 do
-- io.stdout:write(("%d %s\n"):format(i, vim.v.argv[i]))
-- end

@ -186,14 +186,17 @@ M.preprocess = function(opts)
-- if no index was supplied use the last argument
local idx = tonumber(i) and tonumber(i)+6 or #vim.v.argv
if debug then
io.stdout:write(("[DEBUG]: arg(%d) = %s\n")
io.stdout:write(("[DEBUG]: argv(%d) = %s\n")
:format(idx, vim.fn.shellescape(vim.v.argv[idx])))
end
return vim.v.argv[idx]
end
-- live_grep replace pattern with last argument
local argvz = "{argvz}"
-- save our last search argument for resume
if opts.cmd:match("{argvz}") then
if opts.argv_expr and opts.cmd:match(argvz) then
local query = argv(nil, opts.debug)
set_config_section('globals.grep._last_search',
{ query = query, no_esc = true })
@ -212,19 +215,20 @@ M.preprocess = function(opts)
:format(opts.glob_flag, vim.fn.shellescape(s))
end
-- reset argvz so it doesn't get replaced again below
opts.cmd = opts.cmd:gsub("{argvz}",
opts.cmd = opts.cmd:gsub(argvz,
glob_args .. vim.fn.shellescape(search_query))
end
end
-- nifty hack to avoid having to double escape quotations
-- see my comment inside 'live_grep' initial_command code
opts.cmd = opts.cmd:gsub("{argv.*}",
function(x)
local idx = x:match("{argv(.*)}")
return vim.fn.shellescape(argv(idx))
end)
if opts.argv_expr then
opts.cmd = opts.cmd:gsub("{argv.*}",
function(x)
local idx = x:match("{argv(.*)}")
return vim.fn.shellescape(argv(idx))
end)
end
return opts
end

@ -219,6 +219,9 @@ M.live_grep_mt = function(opts)
opts.file_icons = false
end
-- signal to preprocess we are looking to replace {argvz}
opts.argv_expr = true
-- fzf already adds single quotes around the placeholder when expanding
-- for skim we surround it with double quotes or single quote searches fail
local placeholder = utils._if(opts._is_skim, '"{}"', '{q}')

Loading…
Cancel
Save