Files
neovim-config/lua/taken/core/cmd.lua
2025-08-26 11:46:42 +02:00

76 lines
2.0 KiB
Lua

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
-- Groups
local nvimhelp = augroup("help_window_right", { clear = true })
local mkdirrun = augroup("MkdirRun", { clear = true })
local yank = augroup("kickstart-highlight-yank", { clear = true })
local filechange = augroup("filechange", { clear = true })
cmd("SetTheme", function(arg)
local themeselected = arg.fargs[1]
local allthemes = themefuncs.get_all_themes()
if vim.tbl_contains(allthemes, themeselected) then
---@diagnostic disable-next-line: param-type-not-match
themefuncs.change_theme(themeselected)
else
vim.notify("Invalid selection", vim.log.levels.ERROR)
end
end, {
desc = "Select a theme",
nargs = 1,
complete = function()
local getallthemes = themefuncs.get_all_themes()
return getallthemes
end,
})
cmd("ThemeSwitcher", function()
require("taken.utils.themes").themeselector()
end, {
desc = "Open theme selector ui",
})
autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
group = yank,
callback = function()
vim.hl.on_yank()
end,
})
autocmd("BufWinEnter", {
group = nvimhelp,
pattern = { "*.txt" },
callback = function()
if vim.o.filetype == "help" then
vim.cmd.wincmd("L")
end
end,
})
autocmd("BufWritePre", {
group = mkdirrun,
pattern = { "*" },
callback = function()
require("taken.utils.mkdir").run()
end,
})
autocmd("FileChangedShell", {
group = filechange,
pattern = { "*" },
callback = function(args)
--- @type string
local file = args.file
local cwd = vim.fn.getcwd()
if file:find(cwd) then
file = file:sub(#cwd + 2)
end
vim.notify(file .. " has been chnaged", vim.log.levels.WARN)
end,
})