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