Fix sed, fix saveas

This commit is contained in:
lambtho12
2022-01-20 16:58:57 +01:00
parent eba6dcd1d7
commit 840e2b3493

View File

@@ -222,7 +222,6 @@ local escape_chars = function(string)
["*"] = "\\*", ["*"] = "\\*",
["^"] = "\\^", ["^"] = "\\^",
["$"] = "\\$", ["$"] = "\\$",
["/"] = "\\/",
}) })
end end
@@ -231,10 +230,6 @@ local function recursive_substitution(dir, old, new)
return return
end end
if vim.fn.executable("find") == 0 then
vim.api.nvim_err_write("Find not installed!\n")
return
end
if vim.fn.executable("sed") == 0 then if vim.fn.executable("sed") == 0 then
vim.api.nvim_err_write("Sed not installed!\n") vim.api.nvim_err_write("Sed not installed!\n")
return return
@@ -243,16 +238,22 @@ local function recursive_substitution(dir, old, new)
old = escape_chars(old) old = escape_chars(old)
new = escape_chars(new) new = escape_chars(new)
local replace_cmd = "find " local sedcommand = "sed -i"
.. dir if vim.fn.has("mac") == 1 then
.. " -type f -name '*" sedcommand = "sed -i ''"
.. M.Cfg.extension end
.. "' -exec sed -i 's/"
.. old
.. "/"
.. new
.. "/g' {} +"
local replace_cmd = "rg -l -t markdown '"
.. old
.. "' "
.. dir
.. " | xargs "
.. sedcommand
.. " 's|"
.. old
.. "|"
.. new
.. "|g' >/dev/null 2>&1"
os.execute(replace_cmd) os.execute(replace_cmd)
end end
@@ -1500,12 +1501,12 @@ local function RenameNote()
if not (check_dir_and_ask(newpath, "Renamed file")) then if not (check_dir_and_ask(newpath, "Renamed file")) then
return return
end end
vim.cmd("saveas " .. newname .. M.Cfg.extension)
vim.cmd("saveas " .. M.Cfg.home .. "/" .. newname .. M.Cfg.extension)
vim.cmd("bdelete " .. oldfile.title .. M.Cfg.extension) vim.cmd("bdelete " .. oldfile.title .. M.Cfg.extension)
os.execute( os.execute(
"rm " .. M.Cfg.home .. "/" .. oldfile.title .. M.Cfg.extension "rm " .. M.Cfg.home .. "/" .. oldfile.title .. M.Cfg.extension
) )
-- vim.cmd("redraw!")
end end
if M.Cfg.rename_update_links == true then if M.Cfg.rename_update_links == true then