improve method of adding and removing plugins

This commit is contained in:
zbirenbaum 2022-02-13 02:39:07 -05:00 committed by siduck
parent a21e884983
commit f81531df42
2 changed files with 33 additions and 23 deletions

View file

@ -280,23 +280,35 @@ M.tbl_override_req = function(name, default_table)
return vim.tbl_deep_extend("force", default_table, override) return vim.tbl_deep_extend("force", default_table, override)
end end
M.remove_default_plugins = function(plugin_table) --provide labels to plugins instead of integers
local removals = require("core.utils").load_config().plugins.default_plugin_remove or {} M.label_plugins = function(plugins)
local result = {} plugins_labeled = {}
for _, plugin in ipairs(plugins) do
if vim.tbl_isempty(removals) then plugins_labeled[plugin[1]] = plugin
return plugin_table
end end
return plugins_labeled
end
for _, value in pairs(plugin_table) do -- remove plugins specified by user from the plugins table
for _, plugin in ipairs(removals) do M.remove_default_plugins = function(plugins)
if value[1] ~= plugin then local removals = require("core.utils").load_config().plugins.default_plugin_remove or {}
table.insert(result, value) if not vim.tbl_isempty(removals) then
end for _, plugin in pairs(removals) do
plugins[plugin] = nil
end end
end end
return plugins
end
return result -- append user plugins to default plugins
M.add_user_plugins = function(plugins)
local user_Plugins = require("core.utils").load_config().plugins.install or {}
if not vim.tbl_isempty(user_Plugins) then
for _, v in pairs(user_Plugins) do
plugins[v[1]] = v
end
end
return plugins
end end
return M return M

View file

@ -224,18 +224,16 @@ local plugins = {
end, end,
}, },
} }
--label plugins for operational assistance
plugins = require("core.utils").label_plugins(plugins)
--remove plugins specified in chadrc --remove plugins specified in chadrc
plugins = require("core.utils").remove_default_plugins(plugins) plugins = require("core.utils").remove_default_plugins(plugins)
--add plugins specified in chadrc
plugins = require("core.utils").add_user_plugins(plugins)
-- append user plugins to default plugins return packer.startup(function(use)
local user_Plugins = plugin_settings.install for _, v in pairs(plugins_labeled) do
use(v)
if type(user_Plugins) == "table" then
if table.maxn(user_Plugins) == 1 then
plugins[#plugins + 1] = user_Plugins[1]
else
plugins[#plugins + 1] = user_Plugins
end end
end end)
return packer.startup { plugins }