53 lines
1.4 KiB
Lua
53 lines
1.4 KiB
Lua
local M = {}
|
|
|
|
function M.themeselector()
|
|
local configDir = vim.fn.stdpath("config")
|
|
local prefsFile = configDir .. "/lua/taken/prefs.lua"
|
|
local oldstring = 'M.colorscheme = .*"'
|
|
|
|
local colors = vim.fn.globpath(vim.o.rtp, "colors/*", 1, 1)
|
|
local dataDir = vim.fn.stdpath("data")
|
|
local newpath = string.gsub(dataDir, "%-", "%%-")
|
|
local themes = {}
|
|
|
|
for i, v in ipairs(colors) do
|
|
if string.find(v, "lazy") then
|
|
local filename = string.gsub(v, newpath .. "\\lazy\\.*\\", "")
|
|
local themename = string.gsub(filename, ".vim", "")
|
|
local themename2 = string.gsub(themename, ".lua", "")
|
|
|
|
table.insert(themes, themename2)
|
|
end
|
|
end
|
|
|
|
local opts = {
|
|
prompt = "Select a theme",
|
|
}
|
|
|
|
local function change_theme(old, new)
|
|
-- function from nvchad
|
|
local file = io.open(prefsFile, "r")
|
|
local added_pattern = string.gsub(old, "-", "%%-")
|
|
local new_content = file:read("*all"):gsub(added_pattern, new)
|
|
|
|
file = io.open(prefsFile, "w")
|
|
file:write(new_content)
|
|
file:close()
|
|
end
|
|
|
|
local exec = function(choice)
|
|
if choice == nil then
|
|
vim.notify("No theme selected!")
|
|
return
|
|
end
|
|
|
|
vim.cmd("colorscheme " .. choice)
|
|
local newstring = 'M.colorscheme = "' .. choice .. '"'
|
|
change_theme(oldstring, newstring)
|
|
end
|
|
|
|
vim.ui.select(themes, opts, exec)
|
|
end
|
|
|
|
return M
|