Skip to content

Commit

Permalink
Merge pull request #3 from iamando/develop
Browse files Browse the repository at this point in the history
feat: setup nvchad lua config with plugins
  • Loading branch information
andostronaut authored Mar 12, 2024
2 parents b5db80c + 07741cd commit 06f3523
Show file tree
Hide file tree
Showing 18 changed files with 2,355 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.DS_Store
plugin
custom
spell
ftplugin
syntax
coc-settings.json
.luarc.json
lazy-lock.json
after
**/.DS_Store
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "None"
21 changes: 21 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "core"

local custom_init_path = vim.api.nvim_get_runtime_file("lua/custom/init.lua", false)[1]

if custom_init_path then
dofile(custom_init_path)
end

require("core.utils").load_mappings()

local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"

-- bootstrap lazy.nvim!
if not vim.loop.fs_stat(lazypath) then
require("core.bootstrap").gen_chadrc_template()
require("core.bootstrap").lazy(lazypath)
end

dofile(vim.g.base46_cache .. "defaults")
vim.opt.rtp:prepend(lazypath)
require "plugins"
1 change: 1 addition & 0 deletions lua/.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!/lua/custom/
62 changes: 62 additions & 0 deletions lua/core/bootstrap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local M = {}
local fn = vim.fn

M.echo = function(str)
vim.cmd "redraw"
vim.api.nvim_echo({ { str, "Bold" } }, true, {})
end

local function shell_call(args)
local output = fn.system(args)
assert(vim.v.shell_error == 0, "External call failed with error code: " .. vim.v.shell_error .. "\n" .. output)
end

M.lazy = function(install_path)
------------- base46 ---------------
local lazy_path = fn.stdpath "data" .. "/lazy/base46"

M.echo " Compiling base46 theme to bytecode ..."

local base46_repo = "https://github.com/NvChad/base46"
shell_call { "git", "clone", "--depth", "1", "-b", "v2.0", base46_repo, lazy_path }
vim.opt.rtp:prepend(lazy_path)

require("base46").compile()

--------- lazy.nvim ---------------
M.echo " Installing lazy.nvim & plugins ..."
local repo = "https://github.com/folke/lazy.nvim.git"
shell_call { "git", "clone", "--filter=blob:none", "--branch=stable", repo, install_path }
vim.opt.rtp:prepend(install_path)

-- install plugins
require "plugins"

-- mason packages & show post_bootstrap screen
require "nvchad.post_install"()
end

M.gen_chadrc_template = function()
local path = fn.stdpath "config" .. "/lua/custom"

if fn.isdirectory(path) ~= 1 then
local input = fn.input "Do you want to install example custom config? (y/N): "

if input:lower() == "y" then
M.echo "Cloning example custom config repo..."
shell_call { "git", "clone", "--depth", "1", "https://github.com/NvChad/example_config", path }
fn.delete(path .. "/.git", "rf")
else
-- use very minimal chadrc
fn.mkdir(path, "p")

local file = io.open(path .. "/chadrc.lua", "w")
if file then
file:write "---@type ChadrcConfig\nlocal M = {}\n\nM.ui = { theme = 'onedark' }\n\nreturn M"
file:close()
end
end
end
end

return M
92 changes: 92 additions & 0 deletions lua/core/default_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
local M = {}

M.options = {
nvchad_branch = "v2.0",
}

M.ui = {
------------------------------- base46 -------------------------------------
-- hl = highlights
hl_add = {},
hl_override = {},
changed_themes = {},
theme_toggle = { "onedark", "one_light" },
theme = "onedark", -- default theme
transparency = false,
lsp_semantic_tokens = false, -- needs nvim v0.9, just adds highlight groups for lsp semantic tokens

-- https://github.com/NvChad/base46/tree/v2.0/lua/base46/extended_integrations
extended_integrations = {}, -- these aren't compiled by default, ex: "alpha", "notify"

-- cmp themeing
cmp = {
icons = true,
lspkind_text = true,
style = "flat_dark", -- default/flat_light/flat_dark/atom/atom_colored
border_color = "grey_fg", -- only applicable for "default" style, use color names from base30 variables
selected_item_bg = "colored", -- colored / simple
},

telescope = { style = "borderless" }, -- borderless / bordered

------------------------------- nvchad_ui modules -----------------------------
statusline = {
theme = "vscode_colored", -- default/vscode/vscode_colored/minimal
-- default/round/block/arrow separators work only for default statusline theme
-- round and block will work for minimal theme only
separator_style = "default",
overriden_modules = nil,
},

-- lazyload it when there are 1+ buffers
tabufline = {
show_numbers = false,
enabled = true,
lazyload = true,
overriden_modules = nil,
},

-- nvdash (dashboard)
nvdash = {
load_on_startup = true,

header = {
" ▄ ▄ ",
" ▄ ▄▄▄ ▄ ▄▄▄ ▄ ▄ ",
" █ ▄ █▄█ ▄▄▄ █ █▄█ █ █ ",
" ▄▄ █▄█▄▄▄█ █▄█▄█▄▄█▄▄█ █ ",
" ▄ █▄▄█ ▄ ▄▄ ▄█ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ",
" █▄▄▄▄ ▄▄▄ █ ▄ ▄▄▄ ▄ ▄▄▄ ▄ ▄ █ ▄",
"▄ █ █▄█ █▄█ █ █ █▄█ █ █▄█ ▄▄▄ █ █",
"█▄█ ▄ █▄▄█▄▄█ █ ▄▄█ █ ▄ █ █▄█▄█ █",
" █▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ █▄█▄▄▄█ ",
},

buttons = {
{ " Find File", "Spc f f", "Telescope find_files" },
{ "󰈚 Recent Files", "Spc f o", "Telescope oldfiles" },
{ "󰈭 Find Word", "Spc f w", "Telescope live_grep" },
{ " Bookmarks", "Spc m a", "Telescope marks" },
{ " Themes", "Spc t h", "Telescope themes" },
{ " Mappings", "Spc c h", "NvCheatsheet" },
},
},

cheatsheet = { theme = "grid" }, -- simple/grid

lsp = {
-- show function signatures i.e args as you type
signature = {
disabled = false,
silent = true, -- silences 'no signature help available' message from appearing
},
},
}

M.plugins = "" -- path i.e "custom.plugins", so make custom/plugins.lua file

M.lazy_nvim = require "plugins.configs.lazy_nvim" -- config for lazy.nvim startup options

M.mappings = require "core.mappings"

return M
115 changes: 115 additions & 0 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
local opt = vim.opt
local g = vim.g
local config = require("core.utils").load_config()

-------------------------------------- globals -----------------------------------------
g.nvchad_theme = config.ui.theme
g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/"
g.toggle_theme_icon = ""
g.transparency = config.ui.transparency

-------------------------------------- options ------------------------------------------
opt.laststatus = 3 -- global statusline
opt.showmode = false

opt.clipboard = "unnamedplus"
opt.cursorline = true

-- Indenting
opt.expandtab = true
opt.shiftwidth = 2
opt.smartindent = true
opt.tabstop = 2
opt.softtabstop = 2

opt.fillchars = { eob = " " }
opt.ignorecase = true
opt.smartcase = true
opt.mouse = "a"

-- Numbers
opt.number = true
opt.numberwidth = 2
opt.ruler = false

-- disable nvim intro
opt.shortmess:append "sI"

opt.signcolumn = "yes"
opt.splitbelow = true
opt.splitright = true
opt.termguicolors = true
opt.timeoutlen = 400
opt.undofile = true

-- interval for writing swap file to disk, also used by gitsigns
opt.updatetime = 250

-- go to previous/next line with h,l,left arrow and right arrow
-- when cursor reaches end/beginning of line
opt.whichwrap:append "<>[]hl"

g.mapleader = " "

-- disable some default providers
for _, provider in ipairs { "node", "perl", "python3", "ruby" } do
vim.g["loaded_" .. provider .. "_provider"] = 0
end

-- add binaries installed by mason.nvim to path
local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and ";" or ":") .. vim.env.PATH

-------------------------------------- autocmds ------------------------------------------
local autocmd = vim.api.nvim_create_autocmd

-- dont list quickfix buffers
autocmd("FileType", {
pattern = "qf",
callback = function()
vim.opt_local.buflisted = false
end,
})

-- reload some chadrc options on-save
autocmd("BufWritePost", {
pattern = vim.tbl_map(function(path)
return vim.fs.normalize(vim.loop.fs_realpath(path))
end, vim.fn.glob(vim.fn.stdpath "config" .. "/lua/custom/**/*.lua", true, true, true)),
group = vim.api.nvim_create_augroup("ReloadNvChad", {}),

callback = function(opts)
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 module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".")

require("plenary.reload").reload_module "base46"
require("plenary.reload").reload_module(module)
require("plenary.reload").reload_module "custom.chadrc"

config = require("core.utils").load_config()

vim.g.nvchad_theme = config.ui.theme
vim.g.transparency = config.ui.transparency

-- statusline
require("plenary.reload").reload_module("nvchad.statusline." .. config.ui.statusline.theme)
vim.opt.statusline = "%!v:lua.require('nvchad.statusline." .. config.ui.statusline.theme .. "').run()"

-- tabufline
if config.ui.tabufline.enabled then
require("plenary.reload").reload_module "nvchad.tabufline.modules"
vim.opt.tabline = "%!v:lua.require('nvchad.tabufline.modules').run()"
end

require("base46").load_all_highlights()
-- vim.cmd("redraw!")
end,
})

-------------------------------------- commands ------------------------------------------
local new_cmd = vim.api.nvim_create_user_command

new_cmd("NvChadUpdate", function()
require "nvchad.updater"()
end, {})
Loading

0 comments on commit 06f3523

Please sign in to comment.