From 5246faa09a166e4a3b18f7ba4c2056dc5d24222f Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 15 Feb 2023 17:37:10 +0530 Subject: [PATCH] add windows support for compile theme autocmd --- lua/core/bootstrap.lua | 2 +- lua/core/init.lua | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lua/core/bootstrap.lua b/lua/core/bootstrap.lua index 307cad8..84a30a9 100644 --- a/lua/core/bootstrap.lua +++ b/lua/core/bootstrap.lua @@ -25,7 +25,7 @@ M.lazy = function(install_path) require "plugins" vim.fn.mkdir(vim.g.base46_cache, "p") - vim.cmd "CompileNvTheme" + require("base46").load_all_highlights() require("lazy").load { plugins = "nvim-treesitter" } -- install binaries from mason.nvim & tsparsers on LazySync diff --git a/lua/core/init.lua b/lua/core/init.lua index b0ff8d2..6ba5109 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -19,14 +19,37 @@ autocmd("FileType", { end, }) -autocmd("BufWritePost", { - pattern = "*lua", - callback = function() - local bufname = vim.api.nvim_buf_get_name(0) +local sep = vim.loop.os_uname().sysname:find "windows" and "\\" or "/" - if string.find(bufname, "custom") and string.find(bufname, "lua") then - require("plenary.reload").reload_module "base46" - require("base46").load_all_highlights() - end +vim.api.nvim_create_autocmd("BufWritePost", { + pattern = vim.fn.glob( + table.concat({ + vim.fn.stdpath "config", + "lua", + "custom", + "**", + "*.lua", + }, sep), + true, + true, + true + ), + + group = vim.api.nvim_create_augroup("ReloadNvChad", {}), + + callback = function(opts) + require("plenary.reload").reload_module "base46" + local file = string + .gsub(vim.fn.fnamemodify(opts.file, ":r"), vim.fn.stdpath "config" .. sep .. "lua" .. sep, "") + :gsub(sep, ".") + require("plenary.reload").reload_module(file) + require("plenary.reload").reload_module "custom.chadrc" + + local config = require("core.utils").load_config().ui + + vim.opt.statusline = "%!v:lua.require('nvchad_ui.statusline." .. config.statusline.theme .. "').run()" + + require("base46").load_all_highlights() + -- vim.cmd("redraw!") end, })