theme and scripts

This commit is contained in:
Harivansh Rathi 2026-03-20 14:22:40 -04:00
parent deade2bafb
commit 7ae7c1ceec
17 changed files with 575 additions and 270 deletions

View file

@ -1,74 +1,49 @@
return {
{
'harivansh-afk/cozybox.nvim',
lazy = false,
priority = 1000,
config = function()
local function apply_cozybox_overrides()
local links = {
{ 'DiffsAdd', 'DiffAdd' },
{ 'DiffsDelete', 'DiffDelete' },
{ 'DiffsChange', 'DiffChange' },
{ 'DiffsText', 'DiffText' },
{ 'DiffsClear', 'Normal' },
}
for _, pair in ipairs(links) do
vim.api.nvim_set_hl(0, pair[1], { link = pair[2], default = false })
end
end
vim.api.nvim_create_augroup('cozybox_fallback_highlights', { clear = true })
vim.api.nvim_create_autocmd('ColorScheme', {
group = 'cozybox_fallback_highlights',
callback = function()
if vim.g.colors_name == 'cozybox' then
apply_cozybox_overrides()
end
end,
})
vim.cmd.colorscheme('cozybox')
apply_cozybox_overrides()
end,
},
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
config = function()
local theme = {
normal = {
a = { gui = 'bold' },
},
visual = {
a = { gui = 'bold' },
},
replace = {
a = { gui = 'bold' },
},
command = {
a = { gui = 'bold' },
},
}
require('lualine').setup({
options = {
icons_enabled = false,
component_separators = '',
section_separators = { left = '', right = '' },
theme = theme,
},
sections = {
lualine_a = { 'mode' },
lualine_b = { 'FugitiveHead', 'diff' },
lualine_c = { { 'filename', path = 0 } },
lualine_x = { 'diagnostics' },
lualine_y = { 'filetype' },
lualine_z = { 'progress' },
},
})
end,
},
{
'barrettruth/nonicons.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
},
{
dir = vim.fn.expand "~/Documents/GitHub/cozybox.nvim",
name = "cozybox.nvim",
lazy = false,
priority = 1000,
config = function() require("theme").setup() end,
},
{
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
local theme = {
normal = {
a = { gui = "bold" },
},
visual = {
a = { gui = "bold" },
},
replace = {
a = { gui = "bold" },
},
command = {
a = { gui = "bold" },
},
}
require("lualine").setup {
options = {
icons_enabled = false,
component_separators = "",
section_separators = { left = "", right = "" },
theme = theme,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "FugitiveHead", "diff" },
lualine_c = { { "filename", path = 0 } },
lualine_x = { "diagnostics" },
lualine_y = { "filetype" },
lualine_z = { "progress" },
},
}
end,
},
{
"barrettruth/nonicons.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
},
}

88
config/nvim/lua/theme.lua Normal file
View file

@ -0,0 +1,88 @@
local M = {}
local theme_state_file = vim.fn.stdpath "state" .. "/theme/current"
local active_schemes = {
cozybox = true,
["cozybox-light"] = true,
}
local function ensure_server_socket()
if vim.v.servername ~= nil and vim.v.servername ~= "" then
return
end
local socket_path = ("/tmp/nvim-%d.sock"):format(vim.fn.getpid())
vim.fn.serverstart(socket_path)
end
local function apply_cozybox_overrides()
local links = {
{ "DiffsAdd", "DiffAdd" },
{ "DiffsDelete", "DiffDelete" },
{ "DiffsChange", "DiffChange" },
{ "DiffsText", "DiffText" },
{ "DiffsClear", "Normal" },
}
for _, pair in ipairs(links) do
vim.api.nvim_set_hl(0, pair[1], { link = pair[2], default = false })
end
end
local function read_mode()
local ok, lines = pcall(vim.fn.readfile, theme_state_file)
if not ok or not lines or not lines[1] then return "dark" end
local mode = vim.trim(lines[1])
if mode == "light" then return "light" end
return "dark"
end
local function colorscheme_for_mode(mode)
if mode == "light" then return "cozybox-light" end
return "cozybox"
end
function M.apply(mode)
local next_mode = mode or read_mode()
local next_scheme = colorscheme_for_mode(next_mode)
if vim.o.background ~= next_mode then vim.o.background = next_mode end
if vim.g.cozybox_theme_mode ~= next_mode or vim.g.colors_name ~= next_scheme then vim.cmd.colorscheme(next_scheme) end
vim.g.cozybox_theme_mode = next_mode
apply_cozybox_overrides()
end
function M.setup()
local group = vim.api.nvim_create_augroup("cozybox_theme_sync", { clear = true })
ensure_server_socket()
vim.api.nvim_create_autocmd("ColorScheme", {
group = group,
callback = function()
if active_schemes[vim.g.colors_name] then apply_cozybox_overrides() end
end,
})
vim.api.nvim_create_autocmd({ "VimEnter", "FocusGained" }, {
group = group,
callback = function() M.apply() end,
})
vim.api.nvim_create_user_command("ThemeSync", function(opts)
local mode = opts.args ~= "" and opts.args or nil
M.apply(mode)
end, {
nargs = "?",
complete = function() return { "dark", "light" } end,
})
M.apply()
end
return M