Skip to content

Instantly share code, notes, and snippets.

@JackDesBwa
Created July 22, 2026 17:39
Show Gist options
  • Select an option

  • Save JackDesBwa/25ceeae4fd90cf2f839e2d98b92a802c to your computer and use it in GitHub Desktop.

Select an option

Save JackDesBwa/25ceeae4fd90cf2f839e2d98b92a802c to your computer and use it in GitHub Desktop.
auto-theme.nvim.lua
-- Plugin nvim to change nvchad base46 theme, when gsettings notifies color-scheme change
-- See `:h nvui.chadrc.options` and set `base46.theme` and `base46.theme_toggle` options
local function apply_theme(theme)
local dark_theme_name = require('nvconfig').base46.theme_toggle[1]
local current_theme_name = require('nvconfig').base46.theme
local rq_dark = (theme == "prefer-dark")
local is_dark = (current_theme_name == dark_theme_name)
if rq_dark ~= is_dark then
local ok, err = pcall(function()
require("base46").toggle_theme()
end)
end
end
local function start_theme_listener()
local handle = io.popen("gsettings get org.gnome.desktop.interface color-scheme")
if handle then
local result = handle:read("*a")
handle:close()
local initial_theme = result:match("'([^']+)'")
if initial_theme then apply_theme(initial_theme) end
end
if vim.g.autotheme_job_id and vim.g.autotheme_job_id > 0 then
vim.fn.jobstop(vim.g.autotheme_job_id)
vim.g.autotheme_job_id = nil
end
vim.g.autotheme_job_id = vim.fn.jobstart({"gsettings", "monitor", "org.gnome.desktop.interface", "color-scheme"}, {
on_stdout = function(_, data)
if not data then return end
for _, line in ipairs(data) do
local theme = line:match("'([^']+)'")
if theme then
vim.schedule(function() apply_theme(theme) end)
end
end
end,
on_exit = function()
vim.g.autotheme_job_id = nil
end
})
end
return {
{
"local/auto-theme",
dir = vim.fn.stdpath("config") .. "/lua/plugins",
dependencies = { "base46" },
lazy = false,
config = function()
start_theme_listener()
end,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment