boostrap mason packages properly

print some message when nvchad is totally setup
This commit is contained in:
siduck 2023-03-24 04:35:54 +05:30
parent 84bdc2335c
commit 7ec4515179
4 changed files with 31 additions and 21 deletions

View file

@ -16,12 +16,29 @@ M.lazy = function(install_path)
-- install plugins + compile their configs -- install plugins + compile their configs
require "plugins" require "plugins"
vim.api.nvim_buf_delete(0, { force = true }) -- close lazy window vim.api.nvim_buf_delete(0, { force = true }) -- close lazy window
vim.defer_fn(function() -- install mason packages
vim.cmd "silent! MasonInstallAll" vim.schedule(function()
end, 0) vim.cmd "Mason"
local packages = {}
for _, pkg_name in ipairs(vim.g.mason_binaries_list) do
packages[pkg_name] = true
vim.cmd("MasonInstall " .. pkg_name)
end
require("mason-registry"):on("package:install:success", function(pkg)
packages[pkg.name] = nil
if vim.tbl_count(packages) == 0 then
vim.schedule(function()
vim.api.nvim_buf_delete(0, { force = true })
vim.notify("Now please read the docs at nvchad.com!") -- WIP, show a nice screen after it
end)
end
end)
end)
end end
M.gen_chadrc_template = function() M.gen_chadrc_template = function()
@ -40,7 +57,7 @@ M.gen_chadrc_template = function()
"https://github.com/NvChad/example_config", "https://github.com/NvChad/example_config",
vim.fn.stdpath "config" .. "/lua/custom", vim.fn.stdpath "config" .. "/lua/custom",
} }
print "dont forget to read docs from nvchad.com!"
vim.cmd "redraw|echo ''" vim.cmd "redraw|echo ''"
-- delete .git from that repo -- delete .git from that repo
@ -51,16 +68,8 @@ M.gen_chadrc_template = function()
local custom_dir = vim.fn.stdpath "config" .. "/lua/custom/" local custom_dir = vim.fn.stdpath "config" .. "/lua/custom/"
vim.fn.mkdir(custom_dir, "p") vim.fn.mkdir(custom_dir, "p")
local str = [[
local M = {}
M.ui = {
theme = "onedark",
}
return M
]]
local file = io.open(custom_dir .. "chadrc.lua", "w") local file = io.open(custom_dir .. "chadrc.lua", "w")
file:write(str) file:write("local M = {} \n M.ui = { theme = 'onedark' } \n return M")
file:close() file:close()
end end
end end

View file

@ -73,18 +73,17 @@ autocmd("FileType", {
-- reload some chadrc options on-save -- reload some chadrc options on-save
vim.api.nvim_create_autocmd("BufWritePost", { vim.api.nvim_create_autocmd("BufWritePost", {
pattern = vim.tbl_map(vim.fs.normalize, vim.fn.glob( pattern = vim.tbl_map(
vim.fn.stdpath("config") .. "/lua/custom/**/*.lua", vim.fs.normalize,
true, vim.fn.glob(vim.fn.stdpath "config" .. "/lua/custom/**/*.lua", true, true, true)
true, ),
true
)),
group = vim.api.nvim_create_augroup("ReloadNvChad", {}), group = vim.api.nvim_create_augroup("ReloadNvChad", {}),
callback = function(opts) callback = function(opts)
local fp = vim.fn.fnamemodify(vim.fs.normalize(vim.api.nvim_buf_get_name(opts.buf)), ":r") --[[@as string]] local fp = vim.fn.fnamemodify(vim.fs.normalize(vim.api.nvim_buf_get_name(opts.buf)), ":r") --[[@as string]]
local app_name = vim.env.NVIM_APPNAME and vim.env.NVIM_APPNAME or "nvim" local app_name = vim.env.NVIM_APPNAME and vim.env.NVIM_APPNAME or "nvim"
local module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".") local module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".")
require("plenary.reload").reload_module "base46" require("plenary.reload").reload_module "base46"
require("plenary.reload").reload_module(module) require("plenary.reload").reload_module(module)
require("plenary.reload").reload_module "custom.chadrc" require("plenary.reload").reload_module "custom.chadrc"

View file

@ -1,5 +1,5 @@
local options = { local options = {
ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim ensure_installed = { "lua-language-server", "stylua" }, -- not an option from mason.nvim
PATH = "skip", PATH = "skip",

View file

@ -129,6 +129,8 @@ local default_plugins = {
vim.api.nvim_create_user_command("MasonInstallAll", function() vim.api.nvim_create_user_command("MasonInstallAll", function()
vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " ")) vim.cmd("MasonInstall " .. table.concat(opts.ensure_installed, " "))
end, {}) end, {})
vim.g.mason_binaries_list = opts.ensure_installed
end, end,
}, },