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
M.label_plugins = function(plugins)
plugins_labeled = {}
for _, plugin in ipairs(plugins) do
plugins_labeled[plugin[1]] = plugin
end
return plugins_labeled
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 {} local removals = require("core.utils").load_config().plugins.default_plugin_remove or {}
local result = {} if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
plugins[plugin] = nil
end
end
return plugins
end
if vim.tbl_isempty(removals) then -- append user plugins to default plugins
return plugin_table M.add_user_plugins = function(plugins)
end local user_Plugins = require("core.utils").load_config().plugins.install or {}
if not vim.tbl_isempty(user_Plugins) then
for _, value in pairs(plugin_table) do for _, v in pairs(user_Plugins) do
for _, plugin in ipairs(removals) do plugins[v[1]] = v
if value[1] ~= plugin then
table.insert(result, value)
end end
end end
end return plugins
return result
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 }