Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nvim/.config/nvim/after/plugin/starter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require("mini.starter").setup({
section = "Explorer",
},
-- Configuration
{ name = "Theme", action = ":Themery", section = "Config" },
{ name = "Theme", action = ":lua vim.g.theme_picker()", section = "Config" },
{ name = "Pack Update", action = ":lua vim.pack.update()", section = "Config" },
{ name = "Check Health", action = ":checkhealth", section = "Config" },
-- Neovim
Expand Down
219 changes: 132 additions & 87 deletions nvim/.config/nvim/after/plugin/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,139 @@ require("tokyonight")
require("nord").setup({})

local themes = {
{
name = "rose-pine-moon",
colorscheme = "rose-pine-moon",
after = [[
os.execute('alacritty-theme rose-pine-moon > /dev/null 2>&1')
]],
},
{
name = "rose-pine-dawn",
colorscheme = "rose-pine-dawn",
after = [[
os.execute('alacritty-theme rose-pine-dawn > /dev/null 2>&1')
]],
},
{
name = "catppuccin-latte",
colorscheme = "catppuccin-latte",
after = [[
os.execute('alacritty-theme catppuccin-latte > /dev/null 2>&1')
]],
},
{
name = "catppuccin-frappe",
colorscheme = "catppuccin-frappe",
after = [[
os.execute('alacritty-theme catppuccin-frappe > /dev/null 2>&1')
]],
},
{
name = "catppuccin-macchiato",
colorscheme = "catppuccin-macchiato",
after = [[
os.execute('alacritty-theme catppuccin-macchiato > /dev/null 2>&1')
]],
},
{
name = "catppuccin-mocha",
colorscheme = "catppuccin-mocha",
after = [[
os.execute('alacritty-theme catppuccin-mocha > /dev/null 2>&1')
]],
},
{
name = "nord",
colorscheme = "nord",
after = [[
os.execute('alacritty-theme nord > /dev/null 2>&1')
]],
},
{
name = "tokyonight-night",
colorscheme = "tokyonight-night",
after = [[
vim.schedule(function() vim.cmd("colorscheme tokyonight-night") end)
os.execute('alacritty-theme tokyonight_night > /dev/null 2>&1')
]],
},
{
name = "tokyonight-storm",
colorscheme = "tokyonight-storm",
after = [[
vim.schedule(function() vim.cmd("colorscheme tokyonight-storm") end)
os.execute('alacritty-theme tokyonight_storm > /dev/null 2>&1')
]],
},
{
name = "tokyonight-day",
colorscheme = "tokyonight-day",
after = [[
vim.schedule(function() vim.cmd("colorscheme tokyonight-day") end)
os.execute('alacritty-theme tokyonight_day > /dev/null 2>&1')
]],
},
{
name = "tokyonight-moon",
colorscheme = "tokyonight-moon",
after = [[
vim.schedule(function() vim.cmd("colorscheme tokyonight-moon") end)
os.execute('alacritty-theme tokyonight_moon > /dev/null 2>&1')
]],
},
"rose-pine-moon",
"rose-pine-dawn",
"catppuccin-latte",
"catppuccin-frappe",
"catppuccin-macchiato",
"catppuccin-mocha",
"nord",
"tokyonight-night",
"tokyonight-storm",
"tokyonight-day",
"tokyonight-moon",
}

require("themery").setup({
themes = themes,
livePreview = true,
-- Alacritty uses underscores for tokyonight; everything else matches nvim's name.
local alacritty_map = {
["tokyonight-night"] = "tokyonight_night",
["tokyonight-storm"] = "tokyonight_storm",
["tokyonight-day"] = "tokyonight_day",
["tokyonight-moon"] = "tokyonight_moon",
}

local state_file = vim.fn.stdpath("data") .. "/theme.json"

local function apply_alacritty(scheme)
local name = alacritty_map[scheme] or scheme
vim.fn.jobstart({ "alacritty-theme", name }, { detach = true })
end

local function save_theme(scheme)
local f = io.open(state_file, "w")
if f then
f:write(vim.fn.json_encode({ colorscheme = scheme }))
f:close()
end
end

local function load_theme()
local f = io.open(state_file, "r")
if not f then
-- Migrate from themery's state file on first run.
f = io.open(vim.fn.stdpath("data") .. "/themery/state.json", "r")
end
if not f then return end
local content = f:read("*a")
f:close()
local ok, data = pcall(vim.fn.json_decode, content)
if ok and data and data.colorscheme then
pcall(vim.cmd, "colorscheme " .. data.colorscheme)
end
end

local function open_picker()
local original = vim.g.colors_name

local function restore()
if original then
pcall(vim.cmd, "colorscheme " .. original)
end
end

local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")

local function apply_selected()
local sel = action_state.get_selected_entry()
if sel then
pcall(vim.cmd, "colorscheme " .. sel.value)
end
end

pickers.new({}, {
prompt_title = "Theme",
finder = finders.new_table({ results = themes }),
sorter = conf.generic_sorter({}),
attach_mappings = function(prompt_bufnr, map)
local function nav_next()
actions.move_selection_next(prompt_bufnr)
apply_selected()
end

local function nav_prev()
actions.move_selection_previous(prompt_bufnr)
apply_selected()
end

local function confirm()
local sel = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if sel then
pcall(vim.cmd, "colorscheme " .. sel.value)
save_theme(sel.value)
else
restore()
end
end

local function cancel()
actions.close(prompt_bufnr)
restore()
end

map("i", "<C-n>", nav_next)
map("i", "<Down>", nav_next)
map("n", "j", nav_next)
map("n", "<Down>", nav_next)
map("i", "<C-p>", nav_prev)
map("i", "<Up>", nav_prev)
map("n", "k", nav_prev)
map("n", "<Up>", nav_prev)
map("i", "<CR>", confirm)
map("n", "<CR>", confirm)
map("i", "<Esc>", cancel)
map("n", "<Esc>", cancel)
map("i", "<C-c>", cancel)
map("n", "q", cancel)

return true
end,
}):find()
end

-- Expose for mini.starter and other callers.
vim.g.theme_picker = open_picker

vim.api.nvim_create_autocmd("ColorScheme", {
callback = function(ev)
apply_alacritty(ev.match)
end,
})

vim.keymap.set("n", "<leader>t", function()
vim.cmd("Themery")
end, { desc = "Theme picker (Themery)" })
load_theme()

vim.keymap.set("n", "<leader>t", open_picker, { desc = "Theme picker" })
1 change: 0 additions & 1 deletion nvim/.config/nvim/lua/greg/pack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ vim.pack.add({
{ src = gh("nvim-telescope/telescope.nvim"), version = "master" },
{ src = gh("ThePrimeagen/harpoon"), version = "master" },

{ src = gh("zaldih/themery.nvim"), version = "main" },
{ src = gh("xiyaowong/nvim-transparent"), version = "main" },

{ src = gh("rose-pine/neovim"), name = "rose-pine", version = "main" },
Expand Down