theme reload with SIGUSR1

This commit is contained in:
ant 2025-01-04 18:36:49 +01:00
parent 02628f3de3
commit 5c5d33736d

View file

@ -55,12 +55,28 @@ require("lazy").setup(plugins)
vim.cmd.colorscheme "catppuccin" vim.cmd.colorscheme "catppuccin"
-- if $XDG_STATE_HOME/darkmode exists, set dark background, light other wise function set_theme_according_to_darkman()
local path = (vim.fn.getenv("XDG_STATE_HOME") or "~/.local/state") .. "/darkmode" local obj = vim.system({ 'darkman', 'get' }, { text = true }):wait()
if vim.fn.filereadable(path) == 1 then if obj.code == 0 then
opt.background = "dark" local theme = "light"
else if obj.stdout == "dark\n" then
opt.background = "light" theme = "dark"
end
if obj.stdout == "light\n" then
theme = "light"
end end
opt.background = theme
vim.api.nvim_exec_autocmds("ColorScheme", {})
end
end
set_theme_according_to_darkman()
vim.api.nvim_create_autocmd("Signal", {
pattern = "SIGUSR1",
callback = set_theme_according_to_darkman
})
require("mappings") require("mappings")