utils: Improve override functions | Fix nvimtree and statusline config |

Misc

* make more things configurable
* use more generic variable names
* handle some edgecases
* cleanup
* format files
This commit is contained in:
Akianonymus 2022-01-21 17:19:49 +05:30 committed by siduck
parent 82211ed829
commit bccd8e4ab9
10 changed files with 338 additions and 317 deletions

View File

@ -238,30 +238,32 @@ M.fg_bg = function(group, fgcol, bgcol)
end end
-- Override default config of a plugin based on the path provided in the chadrc -- Override default config of a plugin based on the path provided in the chadrc
-- Arguments:
-- FUNCTION: override_req, use `chadrc` plugin config override if present -- 1st - name of plugin
-- name = name inside `default_config` / `chadrc` -- 2nd - default config path
-- default_req = run this if 'name' does not exist in `default_config` / `chadrc` -- 3rd - optional function name which will called from default_config path
-- if override or default_req start with `(`, then strip that and assume override calls a function, not a whole file -- e.g: if given args - "telescope", "plugins.configs.telescope", "setup"
-- then return "require('plugins.configs.telescope').setup()"
-- if 3rd arg not given, then return "require('plugins.configs.telescope')"
-- if override is a table, mark set the override flag for the default config to true -- if override is a table, mark set the override flag for the default config to true
-- override flag being true tells the plugin to call tbl_override_req as part of configuration -- override flag being true tells the plugin to call tbl_override_req as part of configuration
M.override_req = function(name, default_req) M.override_req = function(name, default_config, config_function)
local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] local override, apply_table_override =
local result = default_req require("core.utils").load_config().plugins.default_plugin_config_replace[name], "false"
if type(override) == "string" then local result = default_config
if type(override) == "string" and override ~= "" then
result = override result = override
elseif type(override) == "table" then
apply_table_override = "true"
end end
if string.match(result, "^%(") then result = "('" .. result .. "')"
result = result:sub(2) if type(config_function) == "string" and config_function ~= "" then
result = result:gsub("%)%.", "').", 1) -- add the . to call the functions and concatenate true or false as argument
if type(override) == "table" then result = result .. "." .. config_function .. "(" .. apply_table_override .. ")"
result = result:gsub("%(%)", "(true)", 1)
end
return "require('" .. result
end end
return "require('" .. result .. "')" return "require" .. result
end end
-- Override parts of default config of a plugin based on the table provided in the chadrc -- Override parts of default config of a plugin based on the table provided in the chadrc
@ -271,7 +273,7 @@ end
-- default_table = the default configuration table of the plugin -- default_table = the default configuration table of the plugin
-- returns the modified configuration table -- returns the modified configuration table
M.tbl_override_req = function(name, default_table) M.tbl_override_req = function(name, default_table)
local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] local override = require("core.utils").load_config().plugins.default_plugin_config_replace[name] or {}
return vim.tbl_deep_extend("force", default_table, override) return vim.tbl_deep_extend("force", default_table, override)
end end

View File

@ -1,13 +1,12 @@
local colors = require("colors").get()
local present, bufferline = pcall(require, "bufferline") local present, bufferline = pcall(require, "bufferline")
if not present then if not present then
return return
end end
local M = {} local default = {
colors = require("colors").get(),
local chad_defaults = { }
default = {
options = { options = {
offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
buffer_close_icon = "", buffer_close_icon = "",
@ -47,102 +46,103 @@ local chad_defaults = {
highlights = { highlights = {
background = { background = {
guifg = colors.grey_fg, guifg = default.colors.grey_fg,
guibg = colors.black2, guibg = default.colors.black2,
}, },
-- buffers -- buffers
buffer_selected = { buffer_selected = {
guifg = colors.white, guifg = default.colors.white,
guibg = colors.black, guibg = default.colors.black,
gui = "bold", gui = "bold",
}, },
buffer_visible = { buffer_visible = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.black2, guibg = default.colors.black2,
}, },
-- for diagnostics = "nvim_lsp" -- for diagnostics = "nvim_lsp"
error = { error = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.black2, guibg = default.colors.black2,
}, },
error_diagnostic = { error_diagnostic = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.black2, guibg = default.colors.black2,
}, },
-- close buttons -- close buttons
close_button = { close_button = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.black2, guibg = default.colors.black2,
}, },
close_button_visible = { close_button_visible = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.black2, guibg = default.colors.black2,
}, },
close_button_selected = { close_button_selected = {
guifg = colors.red, guifg = default.colors.red,
guibg = colors.black, guibg = default.colors.black,
}, },
fill = { fill = {
guifg = colors.grey_fg, guifg = default.colors.grey_fg,
guibg = colors.black2, guibg = default.colors.black2,
}, },
indicator_selected = { indicator_selected = {
guifg = colors.black, guifg = default.colors.black,
guibg = colors.black, guibg = default.colors.black,
}, },
-- modified -- modified
modified = { modified = {
guifg = colors.red, guifg = default.colors.red,
guibg = colors.black2, guibg = default.colors.black2,
}, },
modified_visible = { modified_visible = {
guifg = colors.red, guifg = default.colors.red,
guibg = colors.black2, guibg = default.colors.black2,
}, },
modified_selected = { modified_selected = {
guifg = colors.green, guifg = default.colors.green,
guibg = colors.black, guibg = default.colors.black,
}, },
-- separators -- separators
separator = { separator = {
guifg = colors.black2, guifg = default.colors.black2,
guibg = colors.black2, guibg = default.colors.black2,
}, },
separator_visible = { separator_visible = {
guifg = colors.black2, guifg = default.colors.black2,
guibg = colors.black2, guibg = default.colors.black2,
}, },
separator_selected = { separator_selected = {
guifg = colors.black2, guifg = default.colors.black2,
guibg = colors.black2, guibg = default.colors.black2,
}, },
-- tabs -- tabs
tab = { tab = {
guifg = colors.light_grey, guifg = default.colors.light_grey,
guibg = colors.one_bg3, guibg = default.colors.one_bg3,
}, },
tab_selected = { tab_selected = {
guifg = colors.black2, guifg = default.colors.black2,
guibg = colors.nord_blue, guibg = default.colors.nord_blue,
}, },
tab_close = { tab_close = {
guifg = colors.red, guifg = default.colors.red,
guibg = colors.black, guibg = default.colors.black,
}, },
}, },
} }
local M = {}
M.setup = function(override_flag) M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("bufferline", chad_defaults) default = require("core.utils").tbl_override_req("bufferline", default)
end end
bufferline.setup(chad_defaults) bufferline.setup(default)
end end
return M return M

View File

@ -4,11 +4,9 @@ if not present then
return return
end end
local M = {}
vim.opt.completeopt = "menuone,noselect" vim.opt.completeopt = "menuone,noselect"
local chad_defaults = { local default = {
snippet = { snippet = {
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
@ -67,11 +65,12 @@ local chad_defaults = {
}, },
} }
local M = {}
M.setup = function(override_flag) M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_cmp", chad_defaults) default = require("core.utils").tbl_override_req("nvim_cmp", default)
end end
cmp.setup(chad_defaults) cmp.setup(default)
end end
return M return M

View File

@ -3,156 +3,156 @@ if not present then
return return
end end
local M = {} local default = {
colors = require("colors").get(),
}
local colors = require("colors").get() default = {
local chad_defaults = {
override = { override = {
c = { c = {
icon = "", icon = "",
color = colors.blue, color = default.colors.blue,
name = "c", name = "c",
}, },
css = { css = {
icon = "", icon = "",
color = colors.blue, color = default.colors.blue,
name = "css", name = "css",
}, },
deb = { deb = {
icon = "", icon = "",
color = colors.cyan, color = default.colors.cyan,
name = "deb", name = "deb",
}, },
Dockerfile = { Dockerfile = {
icon = "", icon = "",
color = colors.cyan, color = default.colors.cyan,
name = "Dockerfile", name = "Dockerfile",
}, },
html = { html = {
icon = "", icon = "",
color = colors.baby_pink, color = default.colors.baby_pink,
name = "html", name = "html",
}, },
jpeg = { jpeg = {
icon = "", icon = "",
color = colors.dark_purple, color = default.colors.dark_purple,
name = "jpeg", name = "jpeg",
}, },
jpg = { jpg = {
icon = "", icon = "",
color = colors.dark_purple, color = default.colors.dark_purple,
name = "jpg", name = "jpg",
}, },
js = { js = {
icon = "", icon = "",
color = colors.sun, color = default.colors.sun,
name = "js", name = "js",
}, },
kt = { kt = {
icon = "󱈙", icon = "󱈙",
color = colors.orange, color = default.colors.orange,
name = "kt", name = "kt",
}, },
lock = { lock = {
icon = "", icon = "",
color = colors.red, color = default.colors.red,
name = "lock", name = "lock",
}, },
lua = { lua = {
icon = "", icon = "",
color = colors.blue, color = default.colors.blue,
name = "lua", name = "lua",
}, },
mp3 = { mp3 = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "mp3", name = "mp3",
}, },
mp4 = { mp4 = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "mp4", name = "mp4",
}, },
out = { out = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "out", name = "out",
}, },
png = { png = {
icon = "", icon = "",
color = colors.dark_purple, color = default.colors.dark_purple,
name = "png", name = "png",
}, },
py = { py = {
icon = "", icon = "",
color = colors.cyan, color = default.colors.cyan,
name = "py", name = "py",
}, },
["robots.txt"] = { ["robots.txt"] = {
icon = "", icon = "",
color = colors.red, color = default.colors.red,
name = "robots", name = "robots",
}, },
toml = { toml = {
icon = "", icon = "",
color = colors.blue, color = default.colors.blue,
name = "toml", name = "toml",
}, },
ts = { ts = {
icon = "", icon = "",
color = colors.teal, color = default.colors.teal,
name = "ts", name = "ts",
}, },
ttf = { ttf = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "TrueTypeFont", name = "TrueTypeFont",
}, },
rb = { rb = {
icon = "", icon = "",
color = colors.pink, color = default.colors.pink,
name = "rb", name = "rb",
}, },
rpm = { rpm = {
icon = "", icon = "",
color = colors.orange, color = default.colors.orange,
name = "rpm", name = "rpm",
}, },
vue = { vue = {
icon = "", icon = "",
color = colors.vibrant_green, color = default.colors.vibrant_green,
name = "vue", name = "vue",
}, },
woff = { woff = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "WebOpenFontFormat", name = "WebOpenFontFormat",
}, },
woff2 = { woff2 = {
icon = "", icon = "",
color = colors.white, color = default.colors.white,
name = "WebOpenFontFormat2", name = "WebOpenFontFormat2",
}, },
xz = { xz = {
icon = "", icon = "",
color = colors.sun, color = default.colors.sun,
name = "xz", name = "xz",
}, },
zip = { zip = {
icon = "", icon = "",
color = colors.sun, color = default.colors.sun,
name = "zip", name = "zip",
}, },
} },
} }
local M = {}
M.setup = function(override_flag) M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_web_devicons", chad_defaults) default = require("core.utils").tbl_override_req("nvim_web_devicons", default)
end end
icons.setup(chad_defaults) icons.setup(default)
end end
return M return M

View File

@ -1,18 +1,20 @@
local present, nvimtree = pcall(require, "nvim-tree") local present, nvimtree = pcall(require, "nvim-tree")
local conf = require("core.utils").load_config().plugins.options.nvimtree
local git_status = conf.enable_git
local ui = conf.ui
if not present then if not present then
return return
end end
local g = vim.g local g = vim.g
local default = {
conf = require("core.utils").load_config().plugins.options.nvimtree,
}
default = {
git_status = default.conf.enable_git,
ui = default.conf.ui,
}
g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names g.nvim_tree_add_trailing = 0 -- append a trailing slash to folder names
g.nvim_tree_git_hl = git_status g.nvim_tree_git_hl = default.git_status
g.nvim_tree_highlight_opened_files = 0 g.nvim_tree_highlight_opened_files = 0
g.nvim_tree_indent_markers = 1 g.nvim_tree_indent_markers = 1
g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened g.nvim_tree_quit_on_open = 0 -- closes tree when file's opened
@ -26,7 +28,7 @@ g.nvim_tree_window_picker_exclude = {
g.nvim_tree_show_icons = { g.nvim_tree_show_icons = {
folders = 1, folders = 1,
files = 1, files = 1,
git = git_status, git = default.git_status,
} }
g.nvim_tree_icons = { g.nvim_tree_icons = {
@ -51,7 +53,7 @@ g.nvim_tree_icons = {
}, },
} }
local chad_defaults = { default = {
filters = { filters = {
dotfiles = false, dotfiles = false,
}, },
@ -66,17 +68,18 @@ local chad_defaults = {
enable = true, enable = true,
update_cwd = false, update_cwd = false,
}, },
view = ui, view = default.ui,
git = { git = {
ignore = false, ignore = false,
}, },
} }
local M = {}
M.setup = function(override_flag) M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_tree", chad_defaults) default = require("core.utils").tbl_override_req("nvim_tree", default)
end end
nvimtree.setup(chad_defaults) nvimtree.setup(default)
end end
return M return M

View File

@ -7,11 +7,11 @@ M.autopairs = function(override_flag)
local present2, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") local present2, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp")
if present1 and present2 then if present1 and present2 then
local chad_defaults = {fast_wrap = {}} local default = { fast_wrap = {} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_autopairs", chad_defaults) default = require("core.utils").tbl_override_req("nvim_autopairs", default)
end end
autopairs.setup(chad_defaults) autopairs.setup(default)
local cmp = require "cmp" local cmp = require "cmp"
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
@ -26,7 +26,7 @@ M.better_escape = function()
end end
M.blankline = function(override_flag) M.blankline = function(override_flag)
local chad_defaults = { local default = {
indentLine_enabled = 1, indentLine_enabled = 1,
char = "", char = "",
filetype_exclude = { filetype_exclude = {
@ -45,17 +45,17 @@ M.blankline = function(override_flag)
show_first_indent_level = false, show_first_indent_level = false,
} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("indent_blankline", chad_defaults) default = require("core.utils").tbl_override_req("indent_blankline", default)
end end
require("indent_blankline").setup(chad_defaults) require("indent_blankline").setup(default)
end end
M.colorizer = function(override_flag) M.colorizer = function(override_flag)
local present, colorizer = pcall(require, "colorizer") local present, colorizer = pcall(require, "colorizer")
if present then if present then
local chad_defaults = { local default = {
filetypes = { filetypes = {
"*" "*",
}, },
user_default_options = { user_default_options = {
RGB = true, -- #RGB hex codes RGB = true, -- #RGB hex codes
@ -72,9 +72,9 @@ M.colorizer = function(override_flag)
}, },
} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_colorizer", chad_defaults) default = require("core.utils").tbl_override_req("nvim_colorizer", default)
end end
colorizer.setup(chad_defaults["filetypes"], chad_defaults["user_default_options"]) colorizer.setup(default["filetypes"], default["user_default_options"])
vim.cmd "ColorizerReloadAllBuffers" vim.cmd "ColorizerReloadAllBuffers"
end end
end end
@ -82,25 +82,25 @@ end
M.comment = function(override_flag) M.comment = function(override_flag)
local present, nvim_comment = pcall(require, "Comment") local present, nvim_comment = pcall(require, "Comment")
if present then if present then
local chad_defaults = {} local default = {}
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_comment", chad_defaults) default = require("core.utils").tbl_override_req("nvim_comment", default)
end end
nvim_comment.setup(chad_defaults) nvim_comment.setup(default)
end end
end end
M.luasnip = function(override_flag) M.luasnip = function(override_flag)
local present, luasnip = pcall(require, "luasnip") local present, luasnip = pcall(require, "luasnip")
if present then if present then
local chad_defaults = { local default = {
history = true, history = true,
updateevents = "TextChanged,TextChangedI", updateevents = "TextChanged,TextChangedI",
} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("luasnip", chad_defaults) default = require("core.utils").tbl_override_req("luasnip", default)
end end
luasnip.config.set_config(chad_defaults) luasnip.config.set_config(default)
require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path } require("luasnip/loaders/from_vscode").load { paths = chadrc_config.plugins.options.luasnip.snippet_path }
require("luasnip/loaders/from_vscode").load() require("luasnip/loaders/from_vscode").load()
end end
@ -109,7 +109,7 @@ end
M.signature = function(override_flag) M.signature = function(override_flag)
local present, lspsignature = pcall(require, "lsp_signature") local present, lspsignature = pcall(require, "lsp_signature")
if present then if present then
local chad_defaults = { local default = {
bind = true, bind = true,
doc_lines = 0, doc_lines = 0,
floating_window = true, floating_window = true,
@ -127,9 +127,9 @@ M.signature = function(override_flag)
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("signature", chad_defaults) default = require("core.utils").tbl_override_req("signature", default)
end end
lspsignature.setup(chad_defaults) lspsignature.setup(default)
end end
end end
@ -176,7 +176,7 @@ end
M.gitsigns = function(override_flag) M.gitsigns = function(override_flag)
local present, gitsigns = pcall(require, "gitsigns") local present, gitsigns = pcall(require, "gitsigns")
if present then if present then
local chad_defaults = { local default = {
signs = { signs = {
add = { hl = "DiffAdd", text = "", numhl = "GitSignsAddNr" }, add = { hl = "DiffAdd", text = "", numhl = "GitSignsAddNr" },
change = { hl = "DiffChange", text = "", numhl = "GitSignsChangeNr" }, change = { hl = "DiffChange", text = "", numhl = "GitSignsChangeNr" },
@ -186,9 +186,9 @@ M.gitsigns = function(override_flag)
}, },
} }
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("gitsigns", chad_defaults) default = require("core.utils").tbl_override_req("gitsigns", default)
end end
gitsigns.setup(chad_defaults) gitsigns.setup(default)
end end
end end

View File

@ -1,8 +1,16 @@
local colors = require("colors").get() local present, feline = pcall(require, "feline")
local lsp = require "feline.providers.lsp" if not present then
local lsp_severity = vim.diagnostic.severity return
end
local icon_styles = { local default = {
colors = require("colors").get(),
lsp = require "feline.providers.lsp",
lsp_severity = vim.diagnostic.severity,
config = require("core.utils").load_config().plugins.options.statusline,
}
default.icon_styles = {
default = { default = {
left = "", left = "",
right = "", right = "",
@ -43,35 +51,35 @@ local icon_styles = {
}, },
} }
local config = require("core.utils").load_config().plugins.options.statusline
-- statusline style -- statusline style
local user_statusline_style = config.style default.statusline_style = default.icon_styles[default.config.style]
local statusline_style = icon_styles[user_statusline_style]
-- show short statusline on small screens -- show short statusline on small screens
local shortline = config.shortline == false and true default.shortline = default.config.shortline == false and true
-- Initialize the components table -- Initialize the components table
local components = { default.components = {
active = {}, active = {},
} }
local main_icon = { default.main_icon = {
provider = statusline_style.main_icon, provider = default.statusline_style.main_icon,
hl = { hl = {
fg = colors.statusline_bg, fg = default.colors.statusline_bg,
bg = colors.nord_blue, bg = default.colors.nord_blue,
}, },
right_sep = { str = statusline_style.right, hl = { right_sep = {
fg = colors.nord_blue, str = default.statusline_style.right,
bg = colors.lightbg, hl = {
} }, fg = default.colors.nord_blue,
bg = default.colors.lightbg,
},
},
} }
local file_name = { default.file_name = {
provider = function() provider = function()
local filename = vim.fn.expand "%:t" local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e" local extension = vim.fn.expand "%:e"
@ -82,46 +90,49 @@ local file_name = {
end end
return " " .. icon .. " " .. filename .. " " return " " .. icon .. " " .. filename .. " "
end, end,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end, end,
hl = { hl = {
fg = colors.white, fg = default.colors.white,
bg = colors.lightbg, bg = default.colors.lightbg,
}, },
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } }, right_sep = {
str = default.statusline_style.right,
hl = { fg = default.colors.lightbg, bg = default.colors.lightbg2 },
},
} }
local dir_name = { default.dir_name = {
provider = function() provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " " return "" .. dir_name .. " "
end, end,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end, end,
hl = { hl = {
fg = colors.grey_fg2, fg = default.colors.grey_fg2,
bg = colors.lightbg2, bg = default.colors.lightbg2,
}, },
right_sep = { right_sep = {
str = statusline_style.right, str = default.statusline_style.right,
hi = { hi = {
fg = colors.lightbg2, fg = default.colors.lightbg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
}, },
} }
local diff = { default.diff = {
add = { add = {
provider = "git_diff_added", provider = "git_diff_added",
hl = { hl = {
fg = colors.grey_fg2, fg = default.colors.grey_fg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
icon = "", icon = "",
}, },
@ -129,8 +140,8 @@ local diff = {
change = { change = {
provider = "git_diff_changed", provider = "git_diff_changed",
hl = { hl = {
fg = colors.grey_fg2, fg = default.colors.grey_fg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
icon = "", icon = "",
}, },
@ -138,65 +149,65 @@ local diff = {
remove = { remove = {
provider = "git_diff_removed", provider = "git_diff_removed",
hl = { hl = {
fg = colors.grey_fg2, fg = default.colors.grey_fg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
icon = "", icon = "",
}, },
} }
local git_branch = { default.git_branch = {
provider = "git_branch", provider = "git_branch",
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end, end,
hl = { hl = {
fg = colors.grey_fg2, fg = default.colors.grey_fg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
icon = "", icon = "",
} }
local diagnostic = { default.diagnostic = {
errors = { errors = {
provider = "diagnostic_errors", provider = "diagnostic_errors",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR) return default.lsp.diagnostics_exist(default.lsp_severity.ERROR)
end, end,
hl = { fg = colors.red }, hl = { fg = default.colors.red },
icon = "", icon = "",
}, },
warning = { warning = {
provider = "diagnostic_warnings", provider = "diagnostic_warnings",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN) return default.lsp.diagnostics_exist(default.lsp_severity.WARN)
end, end,
hl = { fg = colors.yellow }, hl = { fg = default.colors.yellow },
icon = "", icon = "",
}, },
hint = { hint = {
provider = "diagnostic_hints", provider = "diagnostic_hints",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT) return default.lsp.diagnostics_exist(default.lsp_severity.HINT)
end, end,
hl = { fg = colors.grey_fg2 }, hl = { fg = default.colors.grey_fg2 },
icon = "", icon = "",
}, },
info = { info = {
provider = "diagnostic_info", provider = "diagnostic_info",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO) return default.lsp.diagnostics_exist(default.lsp_severity.INFO)
end, end,
hl = { fg = colors.green }, hl = { fg = default.colors.green },
icon = "", icon = "",
}, },
} }
local lsp_progress = { default.lsp_progress = {
provider = function() provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1] local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -228,13 +239,13 @@ local lsp_progress = {
return "" return ""
end, end,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end, end,
hl = { fg = colors.green }, hl = { fg = default.colors.green },
} }
local lsp_icon = { default.lsp_icon = {
provider = function() provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP" return " LSP"
@ -242,112 +253,112 @@ local lsp_icon = {
return "" return ""
end end
end, end,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end, end,
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, hl = { fg = default.colors.grey_fg2, bg = default.colors.statusline_bg },
} }
local mode_colors = { default.mode_colors = {
["n"] = { "NORMAL", colors.red }, ["n"] = { "NORMAL", default.colors.red },
["no"] = { "N-PENDING", colors.red }, ["no"] = { "N-PENDING", default.colors.red },
["i"] = { "INSERT", colors.dark_purple }, ["i"] = { "INSERT", default.colors.dark_purple },
["ic"] = { "INSERT", colors.dark_purple }, ["ic"] = { "INSERT", default.colors.dark_purple },
["t"] = { "TERMINAL", colors.green }, ["t"] = { "TERMINAL", default.colors.green },
["v"] = { "VISUAL", colors.cyan }, ["v"] = { "VISUAL", default.colors.cyan },
["V"] = { "V-LINE", colors.cyan }, ["V"] = { "V-LINE", default.colors.cyan },
[""] = { "V-BLOCK", colors.cyan }, [""] = { "V-BLOCK", default.colors.cyan },
["R"] = { "REPLACE", colors.orange }, ["R"] = { "REPLACE", default.colors.orange },
["Rv"] = { "V-REPLACE", colors.orange }, ["Rv"] = { "V-REPLACE", default.colors.orange },
["s"] = { "SELECT", colors.nord_blue }, ["s"] = { "SELECT", default.colors.nord_blue },
["S"] = { "S-LINE", colors.nord_blue }, ["S"] = { "S-LINE", default.colors.nord_blue },
[""] = { "S-BLOCK", colors.nord_blue }, [""] = { "S-BLOCK", default.colors.nord_blue },
["c"] = { "COMMAND", colors.pink }, ["c"] = { "COMMAND", default.colors.pink },
["cv"] = { "COMMAND", colors.pink }, ["cv"] = { "COMMAND", default.colors.pink },
["ce"] = { "COMMAND", colors.pink }, ["ce"] = { "COMMAND", default.colors.pink },
["r"] = { "PROMPT", colors.teal }, ["r"] = { "PROMPT", default.colors.teal },
["rm"] = { "MORE", colors.teal }, ["rm"] = { "MORE", default.colors.teal },
["r?"] = { "CONFIRM", colors.teal }, ["r?"] = { "CONFIRM", default.colors.teal },
["!"] = { "SHELL", colors.green }, ["!"] = { "SHELL", default.colors.green },
} }
local chad_mode_hl = function() default.chad_mode_hl = function()
return { return {
fg = mode_colors[vim.fn.mode()][2], fg = default.mode_colors[vim.fn.mode()][2],
bg = colors.one_bg, bg = default.colors.one_bg,
} }
end end
local empty_space = { default.empty_space = {
provider = " " .. statusline_style.left, provider = " " .. default.statusline_style.left,
hl = { hl = {
fg = colors.one_bg2, fg = default.colors.one_bg2,
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
}, },
} }
-- this matches the vi mode color -- this matches the vi mode color
local empty_spaceColored = { default.empty_spaceColored = {
provider = statusline_style.left, provider = default.statusline_style.left,
hl = function() hl = function()
return { return {
fg = mode_colors[vim.fn.mode()][2], fg = default.mode_colors[vim.fn.mode()][2],
bg = colors.one_bg2, bg = default.colors.one_bg2,
} }
end, end,
} }
local mode_icon = { default.mode_icon = {
provider = statusline_style.vi_mode_icon, provider = default.statusline_style.vi_mode_icon,
hl = function() hl = function()
return { return {
fg = colors.statusline_bg, fg = default.colors.statusline_bg,
bg = mode_colors[vim.fn.mode()][2], bg = default.mode_colors[vim.fn.mode()][2],
} }
end, end,
} }
local empty_space2 = { default.empty_space2 = {
provider = function() provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " " return " " .. default.mode_colors[vim.fn.mode()][1] .. " "
end, end,
hl = chad_mode_hl, hl = default.chad_mode_hl,
} }
local separator_right = { default.separator_right = {
provider = statusline_style.left, provider = default.statusline_style.left,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end, end,
hl = { hl = {
fg = colors.grey, fg = default.colors.grey,
bg = colors.one_bg, bg = default.colors.one_bg,
}, },
} }
local separator_right2 = { default.separator_right2 = {
provider = statusline_style.left, provider = default.statusline_style.left,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end, end,
hl = { hl = {
fg = colors.green, fg = default.colors.green,
bg = colors.grey, bg = default.colors.grey,
}, },
} }
local position_icon = { default.position_icon = {
provider = statusline_style.position_icon, provider = default.statusline_style.position_icon,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end, end,
hl = { hl = {
fg = colors.black, fg = default.colors.black,
bg = colors.green, bg = default.colors.green,
}, },
} }
local current_line = { default.current_line = {
provider = function() provider = function()
local current_line = vim.fn.line "." local current_line = vim.fn.line "."
local total_line = vim.fn.line "$" local total_line = vim.fn.line "$"
@ -361,13 +372,13 @@ local current_line = {
return " " .. result .. "%% " return " " .. result .. "%% "
end, end,
enabled = shortline or function(winid) enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end, end,
hl = { hl = {
fg = colors.green, fg = default.colors.green,
bg = colors.one_bg, bg = default.colors.one_bg,
}, },
} }
@ -375,45 +386,53 @@ local function add_table(a, b)
table.insert(a, b) table.insert(a, b)
end end
local M = {}
M.setup = function(override_flag)
if override_flag then
default = require("core.utils").tbl_override_req("feline", default)
end
-- components are divided in 3 sections -- components are divided in 3 sections
local left = {} default.left = {}
local middle = {} default.middle = {}
local right = {} default.right = {}
-- left -- left
add_table(left, main_icon) add_table(default.left, default.main_icon)
add_table(left, file_name) add_table(default.left, default.file_name)
add_table(left, dir_name) add_table(default.left, default.dir_name)
add_table(left, diff.add) add_table(default.left, default.diff.add)
add_table(left, diff.change) add_table(default.left, default.diff.change)
add_table(left, diff.remove) add_table(default.left, default.diff.remove)
add_table(left, diagnostic.error) add_table(default.left, default.diagnostic.error)
add_table(left, diagnostic.warning) add_table(default.left, default.diagnostic.warning)
add_table(left, diagnostic.hint) add_table(default.left, default.diagnostic.hint)
add_table(left, diagnostic.info) add_table(default.left, default.diagnostic.info)
add_table(middle, lsp_progress) add_table(default.middle, default.lsp_progress)
-- right -- right
add_table(right, lsp_icon) add_table(default.right, default.lsp_icon)
add_table(right, git_branch) add_table(default.right, default.git_branch)
add_table(right, empty_space) add_table(default.right, default.empty_space)
add_table(right, empty_spaceColored) add_table(default.right, default.empty_spaceColored)
add_table(right, mode_icon) add_table(default.right, default.mode_icon)
add_table(right, empty_space2) add_table(default.right, default.empty_space2)
add_table(right, separator_right) add_table(default.right, default.separator_right)
add_table(right, separator_right2) add_table(default.right, default.separator_right2)
add_table(right, position_icon) add_table(default.right, default.position_icon)
add_table(right, current_line) add_table(default.right, default.current_line)
components.active[1] = left default.components.active[1] = default.left
components.active[2] = middle default.components.active[2] = default.middle
components.active[3] = right default.components.active[3] = default.right
require("feline").setup { feline.setup {
theme = { theme = {
bg = colors.statusline_bg, bg = default.colors.statusline_bg,
fg = colors.fg, fg = default.colors.fg,
}, },
components = components, components = default.components,
} }
end
return M

View File

@ -4,9 +4,7 @@ if not present then
return return
end end
local M = {} local default = {
local chad_defaults = {
defaults = { defaults = {
vimgrep_arguments = { vimgrep_arguments = {
"rg", "rg",
@ -55,12 +53,13 @@ local chad_defaults = {
}, },
} }
function M.setup(override_flag) local M = {}
M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("telescope", chad_defaults) default = require("core.utils").tbl_override_req("telescope", default)
end end
telescope.setup(chad_defaults) telescope.setup(default)
local extensions = { "themes", "terms" } local extensions = { "themes", "terms" }

View File

@ -4,9 +4,7 @@ if not present then
return return
end end
local M = {} local default = {
local chad_defaults = {
ensure_installed = { ensure_installed = {
"lua", "lua",
"vim", "vim",
@ -17,11 +15,12 @@ local chad_defaults = {
}, },
} }
local M = {}
M.setup = function(override_flag) M.setup = function(override_flag)
if override_flag then if override_flag then
chad_defaults = require("core.utils").tbl_override_req("nvim_treesitter", chad_defaults) default = require("core.utils").tbl_override_req("nvim_treesitter", default)
end end
ts_config.setup(chad_defaults) ts_config.setup(default)
end end
return M return M

View File

@ -32,21 +32,21 @@ return packer.startup(function()
use { use {
"kyazdani42/nvim-web-devicons", "kyazdani42/nvim-web-devicons",
after = "nvim-base16.lua", after = "nvim-base16.lua",
config = override_req("nvim_web_devicons", "(plugins.configs.icons).setup()"), config = override_req("nvim_web_devicons", "plugins.configs.icons", "setup"),
} }
use { use {
"feline-nvim/feline.nvim", "feline-nvim/feline.nvim",
disable = not plugin_settings.status.feline, disable = not plugin_settings.status.feline,
after = "nvim-web-devicons", after = "nvim-web-devicons",
config = override_req("feline", "plugins.configs.statusline"), config = override_req("feline", "plugins.configs.statusline", "setup"),
} }
use { use {
"akinsho/bufferline.nvim", "akinsho/bufferline.nvim",
disable = not plugin_settings.status.bufferline, disable = not plugin_settings.status.bufferline,
after = "nvim-web-devicons", after = "nvim-web-devicons",
config = override_req("bufferline", "(plugins.configs.bufferline).setup()"), config = override_req("bufferline", "plugins.configs.bufferline", "setup"),
setup = function() setup = function()
require("core.mappings").bufferline() require("core.mappings").bufferline()
end, end,
@ -56,20 +56,20 @@ return packer.startup(function()
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
disable = not plugin_settings.status.blankline, disable = not plugin_settings.status.blankline,
event = "BufRead", event = "BufRead",
config = override_req("indent_blankline", "(plugins.configs.others).blankline()"), config = override_req("indent_blankline", "plugins.configs.others", "blankline"),
} }
use { use {
"norcalli/nvim-colorizer.lua", "norcalli/nvim-colorizer.lua",
disable = not plugin_settings.status.colorizer, disable = not plugin_settings.status.colorizer,
event = "BufRead", event = "BufRead",
config = override_req("nvim_colorizer", "(plugins.configs.others).colorizer()"), config = override_req("nvim_colorizer", "plugins.configs.others", "colorizer"),
} }
use { use {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
event = "BufRead", event = "BufRead",
config = override_req("nvim_treesitter", "(plugins.configs.treesitter).setup()"), config = override_req("nvim_treesitter", "plugins.configs.treesitter", "setup"),
} }
-- git stuff -- git stuff
@ -77,7 +77,7 @@ return packer.startup(function()
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
disable = not plugin_settings.status.gitsigns, disable = not plugin_settings.status.gitsigns,
opt = true, opt = true,
config = override_req("gitsigns", "(plugins.configs.others).gitsigns()"), config = override_req("gitsigns", "plugins.configs.others", "gitsigns"),
setup = function() setup = function()
require("core.utils").packer_lazy_load "gitsigns.nvim" require("core.utils").packer_lazy_load "gitsigns.nvim"
end, end,
@ -102,7 +102,7 @@ return packer.startup(function()
"ray-x/lsp_signature.nvim", "ray-x/lsp_signature.nvim",
disable = not plugin_settings.status.lspsignature, disable = not plugin_settings.status.lspsignature,
after = "nvim-lspconfig", after = "nvim-lspconfig",
config = override_req("signature", "(plugins.configs.others).signature()"), config = override_req("signature", "plugins.configs.others", "signature"),
} }
use { use {
@ -118,7 +118,7 @@ return packer.startup(function()
"max397574/better-escape.nvim", "max397574/better-escape.nvim",
disable = not plugin_settings.status.better_escape, disable = not plugin_settings.status.better_escape,
event = "InsertEnter", event = "InsertEnter",
config = override_req("better_escape", "(plugins.configs.others).better_escape()"), config = override_req("better_escape", "plugins.configs.others", "better_escape"),
} }
-- load luasnips + cmp related in insert mode only -- load luasnips + cmp related in insert mode only
@ -133,7 +133,7 @@ return packer.startup(function()
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
after = plugin_settings.options.cmp.lazy_load and "friendly-snippets", after = plugin_settings.options.cmp.lazy_load and "friendly-snippets",
config = override_req("nvim_cmp", "(plugins.configs.cmp).setup()"), config = override_req("nvim_cmp", "plugins.configs.cmp", "setup"),
} }
use { use {
@ -141,7 +141,7 @@ return packer.startup(function()
disable = not plugin_settings.status.cmp, disable = not plugin_settings.status.cmp,
wants = "friendly-snippets", wants = "friendly-snippets",
after = plugin_settings.options.cmp.lazy_load and "nvim-cmp", after = plugin_settings.options.cmp.lazy_load and "nvim-cmp",
config = override_req("luasnip", "(plugins.configs.others).luasnip()"), config = override_req("luasnip", "plugins.configs.others", "luasnip"),
} }
use { use {
@ -178,7 +178,7 @@ return packer.startup(function()
"windwp/nvim-autopairs", "windwp/nvim-autopairs",
disable = not plugin_settings.status.autopairs, disable = not plugin_settings.status.autopairs,
after = plugin_settings.options.cmp.lazy_load and plugin_settings.options.autopairs.loadAfter, after = plugin_settings.options.cmp.lazy_load and plugin_settings.options.autopairs.loadAfter,
config = override_req("nvim_autopairs", "(plugins.configs.others).autopairs()"), config = override_req("nvim_autopairs", "plugins.configs.others", "autopairs"),
} }
use { use {
@ -194,7 +194,7 @@ return packer.startup(function()
"numToStr/Comment.nvim", "numToStr/Comment.nvim",
disable = not plugin_settings.status.comment, disable = not plugin_settings.status.comment,
module = "Comment", module = "Comment",
config = override_req("nvim_comment", "(plugins.configs.others).comment()"), config = override_req("nvim_comment", "plugins.configs.others", "comment"),
setup = function() setup = function()
require("core.mappings").comment() require("core.mappings").comment()
end, end,
@ -207,7 +207,7 @@ return packer.startup(function()
-- only set "after" if lazy load is disabled and vice versa for "cmd" -- only set "after" if lazy load is disabled and vice versa for "cmd"
after = not plugin_settings.options.nvimtree.lazy_load and "nvim-web-devicons", after = not plugin_settings.options.nvimtree.lazy_load and "nvim-web-devicons",
cmd = plugin_settings.options.nvimtree.lazy_load and { "NvimTreeToggle", "NvimTreeFocus" }, cmd = plugin_settings.options.nvimtree.lazy_load and { "NvimTreeToggle", "NvimTreeFocus" },
config = override_req("nvim_tree", "(plugins.configs.nvimtree).setup()"), config = override_req("nvim_tree", "plugins.configs.nvimtree", "setup"),
setup = function() setup = function()
require("core.mappings").nvimtree() require("core.mappings").nvimtree()
end, end,
@ -217,7 +217,7 @@ return packer.startup(function()
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
module = "telescope", module = "telescope",
cmd = "Telescope", cmd = "Telescope",
config = override_req("telescope", "(plugins.configs.telescope).setup()"), config = override_req("telescope", "plugins.configs.telescope", "setup"),
setup = function() setup = function()
require("core.mappings").telescope() require("core.mappings").telescope()
end, end,