diff options
| author | Igor Soarez <igor@soarez.org> | 2026-09-17 19:45:23 +0100 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-09-17 19:45:23 +0100 |
| commit | 13cc065ec014b86369dfe4ad60d1a43fa06fd251 (patch) | |
| tree | 684690c61b7b59758c2aac132c65b81c86de0608 /config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua | |
dotfiles
Shell, editor and terminal configuration, the tools that go with them, and
szecret, an age-based secret manager whose store lives elsewhere.
History restarts here. What came before was not written to be read by
anyone else, and carried machine names, addresses and an encrypted secret
store; it is kept privately instead. What is left is meant to be safe on
any machine, including one whose owner is not me: see CLAUDE.md for the
rule it is written to.
Diffstat (limited to 'config/nvim/local-plugins/cfg-watch/lua/cfg_watch/init.lua')
| -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 |
