grep: better regex handling of . and %

main
bhagwan 2 years ago
parent 11bf4e86a7
commit dc23282b96

@ -235,6 +235,8 @@ M.preprocess = function(opts)
glob_args = glob_args .. ("%s %s ")
:format(opts.glob_flag, vim.fn.shellescape(s))
end
-- gsub doesn't like single % on rhs
search_query = search_query:gsub("%%", "%%%%")
-- reset argvz so it doesn't get replaced again below
opts.cmd = opts.cmd:gsub(argvz,
glob_args .. vim.fn.shellescape(search_query))

@ -267,7 +267,7 @@ M.live_grep_mt = function(opts)
opts.fzf_fn = {}
if opts.exec_empty_query or (opts.search and #opts.search > 0) then
opts.fzf_fn = initial_command:gsub(placeholder,
libuv.shellescape(query))
libuv.shellescape(query:gsub("%%", "%%%%")))
end
opts.fzf_opts['--phony'] = ''
opts.fzf_opts['--query'] = libuv.shellescape(query)

@ -103,8 +103,8 @@ end
function M.rg_escape(str)
if not str then return str end
-- [(~'"\/$?'`*&&||;[]<>)]
-- escape "\~$?*|[()-^"
return str:gsub('[\\~$?*|{\\[()%-^]', function(x)
-- escape "\~$?*|[()^-."
return str:gsub('[\\~$?*|{\\[()^%-%.]', function(x)
return '\\' .. x
end)
end

Loading…
Cancel
Save