diff options
Diffstat (limited to 'config/nvim/local-plugins')
| -rw-r--r-- | config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua b/config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua new file mode 100644 index 0000000..3b5c9d6 --- /dev/null +++ b/config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua @@ -0,0 +1,58 @@ +local M = {} + +local function load_config_path(filepath) + local uv = vim.uv or vim.loop + + if uv.fs_stat(filepath) == nil then + local dir = filepath:match("(.*/)") + if dir and uv.fs_stat(dir) == nil then + assert(uv.fs_mkdir(dir, 448)) -- 0o700 + end + local file, err = io.open(filepath, "w") + if not file then + vim.schedule(function() + vim.notify("Error creating file: " .. filepath .. "\n" .. err, vim.log.levels.ERROR) + end) + return + end + file:write("-- Created by cfg-watch\n") + file:close() + else + vim.schedule(function() + local ok, err = pcall(dofile, filepath) + if not ok then + vim.schedule(function() + vim.notify("Error loading config: " .. filepath .. "\n" .. err, vim.log.levels.ERROR) + end) + end + end) + end +end + +function M.load_colors() + local filepath = vim.fn.stdpath("data") .. "/colors.lua" -- ~/.local/share/nvim/colors.lua + load_config_path(filepath) + + local ok, fwatch = pcall(require, "fwatch") + if ok and fwatch and fwatch.once then + fwatch.once(filepath, { + on_event = function() M.load_colors() end, + on_error = function(err) + vim.notify("fwatch error: " .. err, vim.log.levels.ERROR) + end, + }) + else + vim.notify("cfg-watch: fwatch not available", vim.log.levels.ERROR) + end + + vim.schedule(function() + vim.cmd("hi Normal guibg=NONE ctermbg=NONE") + end) +end + +function M.load_config(name) + local filepath = vim.fn.stdpath("config") .. "/lua/" .. name .. ".lua" + load_config_path(filepath) +end + +return M |
