Skip to content

Commit

Permalink
refactor(nvim): use builtin extension for plugin option proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
spywhere committed Oct 12, 2023
1 parent 16e6ceb commit ac2a53f
Showing 1 changed file with 35 additions and 60 deletions.
95 changes: 35 additions & 60 deletions configs/nvim/lua/lib/plugin-manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,75 +27,50 @@ M.add = function (...)
require('plug').install(...)
end

local proxy = function (_)
local function proxy_to_options(map)
return function (_, options, _, plugin)
local function proxy_key(from, to)
if not plugin[from] then
return
end

local value = plugin[from]
local to_key = to
if type(to_key) == 'function' then
to_key = to_key(value)
local proxy_map = function (backend)
if backend == 'vim-plug' then
return {
branch = 'branch',
tag = 'tag',
commit = 'commit',
run = 'do',
cmd = 'on',
ft = 'for'
}
elseif backend == 'packer.nvim' then
return {
branch = 'branch',
tag = 'tag',
commit = 'commit',
run = 'run',
cmd = 'cmd',
ft = 'ft'
}
elseif backend == 'lazy.nvim' then
return {
branch = 'branch',
tag = function (value)
if string.match(value, '*') then
return 'version'
else
return 'tag'
end
options[to_key] = value
end

for from, to in pairs(map) do
proxy_key(from, to)
end
end
end

return function (hook, ctx)
local map = {}
if ctx.backend == 'vim-plug' then
map = {
branch = 'branch',
tag = 'tag',
commit = 'commit',
run = 'do',
cmd = 'on',
ft = 'for'
}
elseif ctx.backend == 'packer.nvim' then
map = {
branch = 'branch',
tag = 'tag',
commit = 'commit',
run = 'run',
cmd = 'cmd',
ft = 'ft'
}
elseif ctx.backend == 'lazy.nvim' then
map = {
branch = 'branch',
tag = function (value)
if string.match(value, '*') then
return 'version'
else
return 'tag'
end
end,
commit = 'commit',
run = 'build',
cmd = 'cmd',
ft = 'ft'
}
end

hook('plugin_options', proxy_to_options(map))
end,
commit = 'commit',
run = 'build',
cmd = 'cmd',
ft = 'ft'
}
end
end

M.setup = function ()
local plug = require('plug')
plug.setup {
update_branch = 'develop',
backend = plug.backend.lazy {},
extensions = {
proxy {},
plug.extension.proxy(proxy_map),
plug.extension.auto_install {},
plug.extension.skip {},
plug.extension.requires {},
Expand Down

0 comments on commit ac2a53f

Please sign in to comment.