local uname = vim.uv.os_uname() local win32 = uname.sysname:match 'Win' and true or false local wsl = uname.release:match 'WSL2' and true or false local os_background = function () -- Default value local background = 'dark' -- Check for environment override first local override = os.getenv 'NVIM_BACKGROUND' if override then return override end -- First check whether we are on WSL or Windows if win32 or wsl then return 'light' -- This takes around 100ms, too long for code in my startup path -- -- Check if 'reg.exe' is executable -- if vim.fn.executable 'reg.exe' ~= 0 then -- -- Execute command to check if the win32 appearance is set to Dark -- local result = vim.system( -- { 'reg.exe', 'Query', 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v', -- 'AppsUseLightTheme' }, { text = true, timeout = 2000 } ):wait() -- if result.code == 0 and result.stdout and result.stdout:find '0x1' then -- background = 'light' -- end -- end -- Check if 'busctl' is executable (part of systemd) elseif vim.fn.executable 'busctl' ~= 0 then -- Abfrage des standardisierten XDG Color-Schemes local cmd = { 'busctl', '--user', '--expect-reply=true', 'call', 'org.freedesktop.portal.Desktop', '/org/freedesktop/portal/desktop', 'org.freedesktop.portal.Settings', 'Read', 'ss', 'org.freedesktop.appearance', 'color-scheme', } local obj = vim.system( cmd, { text = true, timeout = 2000 } ) local result = obj:wait() if result.code ~= 0 then background = 'dark' else local output = result.stdout or '' -- COSMIC/GNOME liefern meist 'v u 1' für Dark, 'v u 2' für Light (oder 0 für Default) -- Wir suchen nach der Zahl am Ende des Outputs local color_scheme = output:match 'u%s+(%d+)' -- 1 = prefer-dark, 2 = prefer-light, 0 = no-preference if color_scheme == '2' or color_scheme == '0' then background = 'light' else background = 'dark' end end end return background end return { uname = uname, win32 = win32, wsl = wsl, os_background = os_background(), }