Browse Source

utils: improve custom plugins management

my-config
NTBBloodbath 4 years ago
parent
commit
39e504a97a
No known key found for this signature in database GPG Key ID: 18D6730BC846AAC5
  1. 59
      lua/doom/utils/init.lua

59
lua/doom/utils/init.lua

@ -4,9 +4,6 @@
-- License: MIT --
---[[---------------------------------------]]---
--- Require packer so we can use `packer.use` function in `custom_plugins` function
local packer = require('packer')
-------------------- HELPERS --------------------
Api, Cmd, Fn = vim.api, vim.cmd, vim.fn
Keymap, Execute, G = Api.nvim_set_keymap, Api.nvim_command, vim.g
@ -84,64 +81,10 @@ end
-- A better and less primitive implementation of custom plugins in Doom Nvim
function Custom_plugins(plugins)
-- if a plugin have some configs like enabled or requires then we will
-- store them in that table
local plugin_with_configs = {}
-- Valid fields for the plugin table (not the boolean ones), see
-- https://github.com/wbthomason/packer.nvim#specifying-plugins
local plugin_valid_fields = {'branch', 'requires', 'config', 'run'}
if type(plugins) ~= 'string' then
for key, val in pairs(plugins) do
-- Create the correct plugin structure to packer
-- use {
-- url,
-- branch,
-- disable,
-- requires,
-- config,
-- run
-- }
-- Plugin repository
if key == 'repo' then
table.insert(plugin_with_configs, val)
end
-- Plugin branch, dependencies, config and post-install/update hooks
if Has_value(plugin_valid_fields, key) then
plugin_with_configs[key] = val
end
-- If the plugin is enabled or not, false by default
if key == 'enabled' then
if val then
plugin_with_configs['disable'] = false
else
plugin_with_configs['disable'] = true
end
end
local packer = require('packer')
-- If the plugin should be skipped in the updates/syncs,
-- false by default
if key == 'lock' then
if val then
plugin_with_configs['lock'] = true
else
plugin_with_configs['lock'] = false
end
end
end
-- Send the configured plugin to packer
packer.use(plugin_with_configs)
else
-- Send the simple plugins, e.G. those who have not declared with configs
-- 'user/repo' ← simple plugin
-- { 'user/repo', opts } ← configured plugin
packer.use(plugins)
end
end
-- Get current OS, returns 'Other' if the current OS is not recognized
function Get_OS()

Loading…
Cancel
Save