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)
end
M.remove_default_plugins = function(plugin_table)
local removals = require("core.utils").load_config().plugins.default_plugin_remove or {}
local result = {}
if vim.tbl_isempty(removals) then
return plugin_table
--provide labels to plugins instead of integers
M.label_plugins = function(plugins)
plugins_labeled = {}
for _, plugin in ipairs(plugins) do
plugins_labeled[plugin[1]] = plugin
end
return plugins_labeled
end
for _, value in pairs(plugin_table) do
for _, plugin in ipairs(removals) do
if value[1] ~= plugin then
table.insert(result, value)
end
-- remove plugins specified by user from the plugins table
M.remove_default_plugins = function(plugins)
local removals = require("core.utils").load_config().plugins.default_plugin_remove or {}
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
plugins[plugin] = nil
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
return M

View file

@ -224,18 +224,16 @@ local plugins = {
end,
},
}
--label plugins for operational assistance
plugins = require("core.utils").label_plugins(plugins)
--remove plugins specified in chadrc
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
local user_Plugins = plugin_settings.install
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
return packer.startup(function(use)
for _, v in pairs(plugins_labeled) do
use(v)
end
end
return packer.startup { plugins }
end)