Updated theme switcher function
Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
function M.themeselector()
|
||||
local configDir = vim.fn.stdpath("config")
|
||||
local prefsFile = configDir .. "/lua/taken/prefs.lua"
|
||||
|
||||
local themes = {
|
||||
"rose-pine-main",
|
||||
"rose-pine-moon",
|
||||
@@ -31,12 +28,29 @@ function M.themeselector()
|
||||
"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)
|
||||
vim.cmd("colorscheme " .. choice)
|
||||
local newstring = 'M.colorscheme = "' .. choice .. '"'
|
||||
change_theme(oldstring, newstring)
|
||||
end
|
||||
|
||||
vim.ui.select(themes, opts, exec)
|
||||
|
||||
Reference in New Issue
Block a user