From 3ebe12e99d27da69abff1c4c0a07fa7668af8104 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 19 Apr 2024 22:32:17 -0400 Subject: make replaceword safer --- lua/core/misc.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lua') diff --git a/lua/core/misc.lua b/lua/core/misc.lua index 1f6d427..b96855b 100644 --- a/lua/core/misc.lua +++ b/lua/core/misc.lua @@ -14,9 +14,12 @@ end function M.replaceword(old, new) local conf = vim.fn.stdpath("config").."/lua/conf/".."opts.lua" local f = io.open(conf, "r") + if not f then return end local new_content = f:read("*all"):gsub(old, new) + f:close() f = io.open(conf, "w") + if not f then return end f:write(new_content) f:close() end -- cgit v1.2.1