From 54280a3e2a6fc1ed490b3dcdf313fda9347a359f Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 24 Dec 2022 22:33:33 +0530 Subject: [PATCH] add function to install chadrc tempalte during bootstrap --- init.lua | 26 +--------------------- lua/core/bootstrap.lua | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 lua/core/bootstrap.lua diff --git a/init.lua b/init.lua index 5f78b57..80dc54f 100644 --- a/init.lua +++ b/init.lua @@ -14,31 +14,7 @@ local fn = vim.fn local install_path = fn.stdpath "data" .. "/site/pack/packer/opt/packer.nvim" if fn.empty(fn.glob(install_path)) > 0 then - vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" }) - print "Cloning packer .." - fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } - - vim.fn.mkdir(vim.g.base46_cache, "p") - - -- install plugins + compile their configs - vim.cmd "packadd packer.nvim" - - require "plugins" - vim.cmd "PackerSync" - - -- install binaries from mason.nvim & tsparsers - vim.api.nvim_create_autocmd("User", { - pattern = "PackerComplete", - callback = function() - require("base46").load_all_highlights() - - vim.cmd "bw | silent! MasonInstallAll" -- close packer window - require("packer").loader "nvim-treesitter" - - local statusline_theme = require("core.utils").load_config().ui.statusline.theme - vim.opt.statusline = "%!v:lua.require('nvchad_ui.statusline." .. statusline_theme .. "').run()" - end, - }) + require("core.bootstrap").packer(install_path) end local custom_init_path = vim.api.nvim_get_runtime_file("lua/custom/init.lua", false)[1] diff --git a/lua/core/bootstrap.lua b/lua/core/bootstrap.lua new file mode 100644 index 0000000..8800ab9 --- /dev/null +++ b/lua/core/bootstrap.lua @@ -0,0 +1,49 @@ +local M = {} + +vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" }) + +M.packer = function(install_path) + print "Cloning packer .." + vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } + + vim.fn.mkdir(vim.g.base46_cache, "p") + + -- install plugins + compile their configs + vim.cmd "packadd packer.nvim" + require "plugins" + vim.cmd "PackerSync" +end + +M.install_template = function() + if not vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1] then + local input = vim.fn.input "Do you want to install chadrc template? (y/n) : " + + if input == "y" then + -- clone example_config repo + local example_config_url = "https://github.com/NvChad/example_config" + print "cloning chadrc starter template repo...." + vim.fn.system { "git", "clone", "--depth", "1", example_config_url, vim.fn.stdpath "config" .. "/lua/custom" } + + -- delete .git from that repo + vim.loop.fs_rmdir(vim.fn.stdpath "config" .. "/lua/custom/.git") + vim.notify "successfully installed chadrc template!" + end + end +end + +-- install binaries from mason.nvim & tsparsers on PackerComplete +vim.api.nvim_create_autocmd("User", { + pattern = "PackerComplete", + callback = function() + M.install_template() + require("base46").load_all_highlights() + + vim.cmd "bw | silent! MasonInstallAll" -- close packer window + require("packer").loader "nvim-treesitter" + + local statusline_theme = require("core.utils").load_config().ui.statusline.theme + vim.opt.statusline = "%!v:lua.require('nvchad_ui.statusline." .. statusline_theme .. "').run()" + end, +}) + +return M