Updated theme switchers
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
local themefuncs = require("taken.utils.themefuncs")
|
||||||
|
|
||||||
|
-- useful variables
|
||||||
local autocmd = vim.api.nvim_create_autocmd
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
local augroup = vim.api.nvim_create_augroup
|
local augroup = vim.api.nvim_create_augroup
|
||||||
local cmd = vim.api.nvim_create_user_command
|
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 mkdirrun = augroup("MkdirRun", { clear = true })
|
||||||
local yank = augroup("kickstart-highlight-yank", { clear = true })
|
local yank = augroup("kickstart-highlight-yank", { clear = true })
|
||||||
|
|
||||||
cmd("ThemeSwitcher", function()
|
cmd("SetTheme", function(arg)
|
||||||
require("taken.utils.themes").themeselector()
|
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, {
|
end, {
|
||||||
desc = "Select a theme",
|
desc = "Select a theme",
|
||||||
|
nargs = 1,
|
||||||
|
complete = function()
|
||||||
|
local getallthemes = themefuncs.getAllThemes()
|
||||||
|
return getallthemes
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
autocmd("TextYankPost", {
|
autocmd("TextYankPost", {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
local oldstring = 'M.colorscheme = .*"'
|
local oldstring = 'M.colorscheme = .*"'
|
||||||
|
local configDir = vim.fn.stdpath("config")
|
||||||
|
local prefsFile = configDir .. "/lua/taken/prefs.lua"
|
||||||
|
|
||||||
|
--- themes
|
||||||
|
--- @return table
|
||||||
local getAllThemes = function()
|
local getAllThemes = function()
|
||||||
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
|
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
|
||||||
|
|
||||||
@@ -26,7 +30,10 @@ local getAllThemes = function()
|
|||||||
return themes
|
return themes
|
||||||
end
|
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
|
-- function from nvchad
|
||||||
local file = io.open(prefsFile, "r")
|
local file = io.open(prefsFile, "r")
|
||||||
local added_pattern = string.gsub(old, "-", "%%-")
|
local added_pattern = string.gsub(old, "-", "%%-")
|
||||||
@@ -37,7 +44,9 @@ local change_theme = function(old, new, prefsFile)
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local applytofile = function(choice, prefsFile)
|
--- applytofile
|
||||||
|
--- @param choice string
|
||||||
|
local applytofile = function(choice)
|
||||||
if choice == nil then
|
if choice == nil then
|
||||||
vim.notify("No theme selected!", 4)
|
vim.notify("No theme selected!", 4)
|
||||||
return
|
return
|
||||||
@@ -45,7 +54,7 @@ local applytofile = function(choice, prefsFile)
|
|||||||
|
|
||||||
vim.cmd("colorscheme " .. choice)
|
vim.cmd("colorscheme " .. choice)
|
||||||
local newstring = 'M.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")
|
local cursorcolumncolor = vim.fn.synIDattr(vim.fn.hlID("CursorColumn"), "bg")
|
||||||
if cursorcolumncolor ~= "" then
|
if cursorcolumncolor ~= "" then
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ function M.themeselector(opts)
|
|||||||
local action_state = require("telescope.actions.state")
|
local action_state = require("telescope.actions.state")
|
||||||
-- local action_set = require("telescope.actions.set")
|
-- 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 themes = themefuncs.getAllThemes()
|
||||||
local applytofile = themefuncs.applytofile
|
local applytofile = themefuncs.applytofile
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user