local M = {} function M.themeselector() local themes = { "rose-pine-main", "rose-pine-moon", "rose-pine-dawn", "catppuccin-mocha", "catppuccin-latte", "nightfly", "tokyonight-night", "tokyonight-storm", "tokyonight-moon", "tokyonight-day", "dracula", "dracula-soft", "OceanicNext", "onelight", "onedark", "onedark_dark", "onedark_vivid", "doom-one", "moonlight", "mellow", "ofirkai", "kanagawa-lotus", "kanagawa-dragon", "kanagawa-wave", } local configDir = vim.fn.stdpath("config") local prefsFile = configDir .. "/lua/taken/prefs.lua" local oldstring = 'M.colorscheme = .*"' 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