From 5c5d33736d9d23ea0b805123e359538064ebce29 Mon Sep 17 00:00:00 2001 From: ant Date: Sat, 4 Jan 2025 18:36:49 +0100 Subject: [PATCH] theme reload with SIGUSR1 --- init.lua | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 49ca285..da33783 100644 --- a/init.lua +++ b/init.lua @@ -55,12 +55,28 @@ require("lazy").setup(plugins) vim.cmd.colorscheme "catppuccin" --- if $XDG_STATE_HOME/darkmode exists, set dark background, light other wise -local path = (vim.fn.getenv("XDG_STATE_HOME") or "~/.local/state") .. "/darkmode" -if vim.fn.filereadable(path) == 1 then - opt.background = "dark" -else - opt.background = "light" +function set_theme_according_to_darkman() + local obj = vim.system({ 'darkman', 'get' }, { text = true }):wait() + if obj.code == 0 then + local theme = "light" + if obj.stdout == "dark\n" then + theme = "dark" + end + if obj.stdout == "light\n" then + theme = "light" + 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")