Updated theme switchers

This commit is contained in:
2024-10-15 19:09:57 +02:00
parent d27fa532dc
commit 0d5eb1e82c
3 changed files with 30 additions and 8 deletions

View File

@@ -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", {

View File

@@ -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

View File

@@ -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