diff --git a/lua/taken/core/cmd.lua b/lua/taken/core/cmd.lua index 63b7c99..86bfbff 100644 --- a/lua/taken/core/cmd.lua +++ b/lua/taken/core/cmd.lua @@ -1,3 +1,6 @@ +local themefuncs = require("taken.utils.themefuncs") + +-- useful variables local autocmd = vim.api.nvim_create_autocmd local augroup = vim.api.nvim_create_augroup local cmd = vim.api.nvim_create_user_command @@ -6,10 +9,23 @@ local nvimhelp = augroup("help_window_right", { clear = true }) local mkdirrun = augroup("MkdirRun", { clear = true }) local yank = augroup("kickstart-highlight-yank", { clear = true }) -cmd("ThemeSwitcher", function() - require("taken.utils.themes").themeselector() +cmd("SetTheme", function(arg) + local themeselected = arg.fargs[1] + + local getallthemes = themefuncs.getAllThemes() + for _, theme in ipairs(getallthemes) do + if theme == themeselected then + vim.cmd("colorscheme " .. themeselected) + themefuncs.applytofile(themeselected) + end + end end, { desc = "Select a theme", + nargs = 1, + complete = function() + local getallthemes = themefuncs.getAllThemes() + return getallthemes + end, }) autocmd("TextYankPost", { diff --git a/lua/taken/utils/themefuncs.lua b/lua/taken/utils/themefuncs.lua index d265204..8ddd39f 100644 --- a/lua/taken/utils/themefuncs.lua +++ b/lua/taken/utils/themefuncs.lua @@ -1,5 +1,9 @@ local oldstring = 'M.colorscheme = .*"' +local configDir = vim.fn.stdpath("config") +local prefsFile = configDir .. "/lua/taken/prefs.lua" +--- themes +--- @return table local getAllThemes = function() vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false }) @@ -26,7 +30,10 @@ local getAllThemes = function() return themes end -local change_theme = function(old, new, prefsFile) +--- change theme +--- @param old string +--- @param new string +local change_theme = function(old, new) -- function from nvchad local file = io.open(prefsFile, "r") local added_pattern = string.gsub(old, "-", "%%-") @@ -37,7 +44,9 @@ local change_theme = function(old, new, prefsFile) file:close() end -local applytofile = function(choice, prefsFile) +--- applytofile +--- @param choice string +local applytofile = function(choice) if choice == nil then vim.notify("No theme selected!", 4) return @@ -45,7 +54,7 @@ local applytofile = function(choice, prefsFile) vim.cmd("colorscheme " .. choice) local newstring = 'M.colorscheme = "' .. choice .. '"' - change_theme(oldstring, newstring, prefsFile) + change_theme(oldstring, newstring) local cursorcolumncolor = vim.fn.synIDattr(vim.fn.hlID("CursorColumn"), "bg") if cursorcolumncolor ~= "" then diff --git a/lua/taken/utils/themes.lua b/lua/taken/utils/themes.lua index 0b4cba9..ade70b1 100644 --- a/lua/taken/utils/themes.lua +++ b/lua/taken/utils/themes.lua @@ -9,9 +9,6 @@ function M.themeselector(opts) local action_state = require("telescope.actions.state") -- local action_set = require("telescope.actions.set") - local configDir = vim.fn.stdpath("config") - local prefsFile = configDir .. "/lua/taken/prefs.lua" - local themes = themefuncs.getAllThemes() local applytofile = themefuncs.applytofile