mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
refact: grep_escape
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
-- Prints a basic error message
|
||||
local function print_error(s)
|
||||
function M.print_error(s)
|
||||
vim.cmd("echohl ErrorMsg")
|
||||
vim.cmd("echomsg " .. '"' .. s .. '"')
|
||||
vim.cmd("echohl None")
|
||||
@@ -18,4 +18,23 @@ function M.strip(s, chars_to_remove)
|
||||
return s:gsub("[" .. M.escape(chars_to_remove) .. "]", "")
|
||||
end
|
||||
|
||||
-- Escapes for regex functions like grep or rg
|
||||
function M.grep_escape(s)
|
||||
return s:gsub("[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%/]", {
|
||||
["\\"] = "\\\\",
|
||||
["-"] = "\\-",
|
||||
["("] = "\\(",
|
||||
[")"] = "\\)",
|
||||
["["] = "\\[",
|
||||
["]"] = "\\]",
|
||||
["{"] = "\\{",
|
||||
["}"] = "\\}",
|
||||
["?"] = "\\?",
|
||||
["+"] = "\\+",
|
||||
["*"] = "\\*",
|
||||
["^"] = "\\^",
|
||||
["$"] = "\\$",
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user