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 ") glob_args = glob_args .. ("%s %s ")
:format(opts.glob_flag, vim.fn.shellescape(s)) :format(opts.glob_flag, vim.fn.shellescape(s))
end end
-- gsub doesn't like single % on rhs
search_query = search_query:gsub("%%", "%%%%")
-- reset argvz so it doesn't get replaced again below -- 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)) glob_args .. vim.fn.shellescape(search_query))

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

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

Loading…
Cancel
Save