From 59fcd66723442227f8b367008faa91ae6fe2643f Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 17 Sep 2023 15:03:40 +0200 Subject: [PATCH] Updated theme switcher function Signed-off-by: Taken --- lua/taken/functions/themes.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/taken/functions/themes.lua b/lua/taken/functions/themes.lua index 5a93247..7bb0347 100644 --- a/lua/taken/functions/themes.lua +++ b/lua/taken/functions/themes.lua @@ -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)