···4040 is_dark = result:match("Dark") ~= nil
4141 elseif vim.fn.has("unix") == 1 then
4242 -- Linux: check if running under a dark theme
4343- -- Try multiple methods to detect dark theme
4444- local methods = {
4545- -- GNOME/GTK
4646- "gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null",
4747- "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null",
4848- -- KDE
4949- "kreadconfig5 --file kdeglobals --group General --key ColorScheme 2>/dev/null",
5050- -- Check if COLORFGBG suggests dark background
5151- function()
5252- local colorfgbg = vim.env.COLORFGBG
5353- if colorfgbg then
5454- local fg, bg = colorfgbg:match("(%d+);(%d+)")
5555- if fg and bg then
5656- -- If foreground is lighter than background, likely dark theme
5757- return tonumber(fg) > tonumber(bg)
4343+ -- Check NixOS theme system first (always check this fresh)
4444+ local f = io.open("/var/theme/current_theme", "r")
4545+ if f then
4646+ local content = f:read("*all"):gsub("^%s+", ""):gsub("%s+$", "")
4747+ f:close()
4848+ is_dark = (content == "dark")
4949+ else
5050+ -- Fallback to other methods if theme file doesn't exist
5151+ local methods = {
5252+ -- GNOME/GTK
5353+ "gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null",
5454+ "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null",
5555+ -- KDE
5656+ "kreadconfig5 --file kdeglobals --group General --key ColorScheme 2>/dev/null",
5757+ -- Check if COLORFGBG suggests dark background
5858+ function()
5959+ local colorfgbg = vim.env.COLORFGBG
6060+ if colorfgbg then
6161+ local fg, bg = colorfgbg:match("(%d+);(%d+)")
6262+ if fg and bg then
6363+ -- If foreground is lighter than background, likely dark theme
6464+ return tonumber(fg) > tonumber(bg)
6565+ end
5866 end
6767+ return false
5968 end
6060- return false
6161- end
6262- }
6969+ }
63706464- for _, method in ipairs(methods) do
6565- if type(method) == "function" then
6666- is_dark = method()
6767- if is_dark then break end
6868- else
6969- local result = vim.fn.system(method)
7070- if result:match("[Dd]ark") or result:match("prefer%-dark") then
7171- is_dark = true
7272- break
7171+ for _, method in ipairs(methods) do
7272+ if type(method) == "function" then
7373+ is_dark = method()
7474+ if is_dark then break end
7575+ else
7676+ local result = vim.fn.system(method)
7777+ if result:match("[Dd]ark") or result:match("prefer%-dark") then
7878+ is_dark = true
7979+ break
8080+ end
7381 end
7482 end
7583 end
···83918492 if is_dark then
8593 vim.cmd("colorscheme ayu")
8686- print("Switched to dark theme (ayu)")
8794 else
8895 vim.cmd("colorscheme everforest")
8989- print("Switched to light theme (everforest)")
9096 end
9197 end
9298 end