escape special chars before search so we can grep [(...)]

main
bhagwan 3 years ago
parent 1de8269b56
commit fe0b3d1184

@ -46,6 +46,10 @@ M.grep = function(opts)
"rg_opts", "grep_opts",
})
if opts.search and #opts.search>0 then
opts.search = utils.rg_escape(opts.search)
end
if opts.repeat_last_search == true then
opts.search = config.grep.last_search
end
@ -103,6 +107,10 @@ M.live_grep = function(opts)
"rg_opts", "grep_opts",
})
if opts.search and #opts.search>0 then
opts.search = utils.rg_escape(opts.search)
end
-- resetting last_search will return
-- {q} placeholder in our command
opts.last_search = opts.search

@ -48,6 +48,14 @@ function M.is_git_repo()
return M._if(M.shell_error(), false, true)
end
function M.rg_escape(str)
-- [(~'"\/$?'`*&&||;[]<>)]
-- escape "\~$?*|[()"
return str:gsub("[\\~$?*|\\[()]", function(x)
return '\\' .. x
end)
end
M.read_file = function(filepath)
local fd = vim.loop.fs_open(filepath, "r", 438)
if fd == nil then return '' end

Loading…
Cancel
Save