mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 05:07:59 +08:00
feat(nvim-plug): add new plugin manager
This commit is contained in:
parent
ac552a4746
commit
d4ce80ba93
20
.ci/detach_plugin.sh
vendored
20
.ci/detach_plugin.sh
vendored
@ -136,6 +136,26 @@ main () {
|
|||||||
_detact_bundle dein-ui.vim README.md
|
_detact_bundle dein-ui.vim README.md
|
||||||
_detact_bundle dein-ui.vim plugin/deinui.vim
|
_detact_bundle dein-ui.vim plugin/deinui.vim
|
||||||
;;
|
;;
|
||||||
|
nvim-plug)
|
||||||
|
git clone https://github.com/wsdjeg/nvim-plug.git detach/$1
|
||||||
|
cd detach/$1
|
||||||
|
_checkdir lua/spacevim/api
|
||||||
|
_detact lua/spacevim/api/job.lua
|
||||||
|
_detact lua/spacevim/api/notify.lua
|
||||||
|
_detact lua/spacevim/api/password.lua
|
||||||
|
_detact LICENSE
|
||||||
|
_detact_bundle $1 README.md
|
||||||
|
_checkdir plugin
|
||||||
|
_detact_bundle $1 plugin/plug.lua
|
||||||
|
_checkdir lua/plug
|
||||||
|
_detact_bundle $1 lua/plug/config.lua
|
||||||
|
_detact_bundle $1 lua/plug/hooks.lua
|
||||||
|
_detact_bundle $1 lua/plug/init.lua
|
||||||
|
_detact_bundle $1 lua/plug/instealler.lua
|
||||||
|
_detact_bundle $1 lua/plug/loader.lua
|
||||||
|
_checkdir test
|
||||||
|
_detact_bundle $1 test/init.lua
|
||||||
|
;;
|
||||||
format.nvim)
|
format.nvim)
|
||||||
git clone https://github.com/wsdjeg/format.nvim.git detach/$1
|
git clone https://github.com/wsdjeg/format.nvim.git detach/$1
|
||||||
cd detach/$1
|
cd detach/$1
|
||||||
|
47
bundle/nvim-plug/README.md
vendored
Normal file
47
bundle/nvim-plug/README.md
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# nvim-plug
|
||||||
|
|
||||||
|
> _nvim-plug_ is a simple plugin manager for neovim
|
||||||
|
|
||||||
|
[![](https://spacevim.org/img/build-with-SpaceVim.svg)](https://spacevim.org)
|
||||||
|
[![GPLv3 License](https://img.spacevim.org/license-GPLv3-blue.svg)](LICENSE)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require("plug").setup({
|
||||||
|
|
||||||
|
bundle_dir = "D:\\bundle_dir\\",
|
||||||
|
})
|
||||||
|
|
||||||
|
require("plug").add({
|
||||||
|
{
|
||||||
|
"wsdjeg/scrollbar.vim",
|
||||||
|
events = { "VimEnter" },
|
||||||
|
config = function() end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wsdjeg/flygrep.nvim",
|
||||||
|
cmds = { "FlyGrep" },
|
||||||
|
config = function()
|
||||||
|
require("flygrep").setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Plugin Spec
|
||||||
|
|
||||||
|
| name | description |
|
||||||
|
| ------ | ------------------------------------------------------- |
|
||||||
|
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||||
|
| `cmds` | `table<string>`, commands lazy loading |
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
- `:PlugInstall`: install specific plugin
|
||||||
|
|
||||||
|
## Feedback
|
||||||
|
|
||||||
|
The development of this plugin is in [`SpaceVim/bundle/nvim-plug`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/nvim-plug) directory.
|
||||||
|
|
||||||
|
If you encounter any bugs or have suggestions, please file an issue in the [issue tracker](https://github.com/SpaceVim/SpaceVim/issues)
|
17
bundle/nvim-plug/lua/plug/config.lua
vendored
Normal file
17
bundle/nvim-plug/lua/plug/config.lua
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- config.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.bundle_dir = vim.fn.stdpath('data') .. '/bundle_dir'
|
||||||
|
|
||||||
|
function M.setup(opt)
|
||||||
|
M.bundle_dir = opt.bundle_dir or M.bundle_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
38
bundle/nvim-plug/lua/plug/hooks.lua
vendored
Normal file
38
bundle/nvim-plug/lua/plug/hooks.lua
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
local group = vim.api.nvim_create_augroup("plugin_hooks", { clear = true })
|
||||||
|
|
||||||
|
local plugin_loader = require("plug.loader")
|
||||||
|
|
||||||
|
local event_plugins = {}
|
||||||
|
local cmd_plugins = {}
|
||||||
|
|
||||||
|
function M.on_events(events, plugSpec)
|
||||||
|
event_plugins[plugSpec.name] = vim.api.nvim_create_autocmd(events, {
|
||||||
|
group = group,
|
||||||
|
pattern = { "*" },
|
||||||
|
callback = function(_)
|
||||||
|
vim.api.nvim_del_autocmd(event_plugins[plugSpec.name])
|
||||||
|
plugin_loader.load(plugSpec)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param cmds table<string>
|
||||||
|
--- @param plugSpec PluginSpec
|
||||||
|
function M.on_cmds(cmds, plugSpec)
|
||||||
|
for _, cmd in ipairs(cmds) do
|
||||||
|
cmd_plugins[cmd] = plugSpec
|
||||||
|
vim.api.nvim_create_user_command(cmd, function(opt)
|
||||||
|
plugin_loader.load(cmd_plugins[opt.name])
|
||||||
|
vim.cmd(opt.name .. ' ' .. opt.args)
|
||||||
|
end, {
|
||||||
|
nargs = "*",
|
||||||
|
complete = function(...)
|
||||||
|
return {}
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
42
bundle/nvim-plug/lua/plug/init.lua
vendored
Normal file
42
bundle/nvim-plug/lua/plug/init.lua
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- plug.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local all_plugins = {}
|
||||||
|
|
||||||
|
local hooks = require("plug.hooks")
|
||||||
|
local loader = require("plug.loader")
|
||||||
|
local config = require("plug.config")
|
||||||
|
|
||||||
|
function M.setup(opt)
|
||||||
|
config.setup(opt)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- @param plugins table<PluginSpec>
|
||||||
|
function M.add(plugins)
|
||||||
|
for _, plug in ipairs(plugins) do
|
||||||
|
loader.parser(plug)
|
||||||
|
all_plugins[plug.name] = plug
|
||||||
|
if plug.cmds then
|
||||||
|
hooks.on_cmds(plug.cmds, plug)
|
||||||
|
end
|
||||||
|
if plug.events then
|
||||||
|
hooks.on_events(plug.events, plug)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not plug.events and not plug.cmds then
|
||||||
|
loader.load(plug)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get()
|
||||||
|
return all_plugins
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
55
bundle/nvim-plug/lua/plug/installer.lua
vendored
Normal file
55
bundle/nvim-plug/lua/plug/installer.lua
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- installer.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local job = require("spacevim.api.job")
|
||||||
|
local notify = require("spacevim.api.notify")
|
||||||
|
local jobs = {}
|
||||||
|
|
||||||
|
local function install_plugin(plugSpec)
|
||||||
|
local cmd = { "git", "clone", "--depth", "1" }
|
||||||
|
if plugSpec.branch then
|
||||||
|
table.insert(cmd, "--branch")
|
||||||
|
table.insert(cmd, plugSpec.branch)
|
||||||
|
elseif plugSpec.tag then
|
||||||
|
table.insert(cmd, "--branch")
|
||||||
|
table.insert(cmd, plugSpec.tag)
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(cmd, plugSpec.url)
|
||||||
|
table.insert(cmd, plugSpec.path)
|
||||||
|
vim.print(plugSpec)
|
||||||
|
local jobid = job.start(cmd, {
|
||||||
|
on_stdout = function(id, data)
|
||||||
|
for _, v in ipairs(data) do
|
||||||
|
notify.notify(jobs['jobid_' .. id .. ':' .. v])
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_stderr = function(id, data)
|
||||||
|
for _, v in ipairs(data) do
|
||||||
|
notify.notify(jobs['jobid_' .. id .. ':' .. v])
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_exit = function(id, data, single)
|
||||||
|
if data == 0 and single == 0 then
|
||||||
|
notify.notify('Successfully installed ' .. jobs['jobid_' .. id])
|
||||||
|
else
|
||||||
|
notify.notify('failed to install ' .. jobs['jobid_' .. id])
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
jobs['jobid_' .. jobid] = plugSpec.name
|
||||||
|
end
|
||||||
|
|
||||||
|
M.install = function(plugSpecs)
|
||||||
|
for _, v in ipairs(plugSpecs) do
|
||||||
|
install_plugin(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
69
bundle/nvim-plug/lua/plug/loader.lua
vendored
Normal file
69
bundle/nvim-plug/lua/plug/loader.lua
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- loader.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local config = require("plug.config")
|
||||||
|
|
||||||
|
--- @class PluginSpec
|
||||||
|
--- @field rtp string
|
||||||
|
--- @field events table<string>
|
||||||
|
--- @field cmds table<string>
|
||||||
|
--- @field config function
|
||||||
|
|
||||||
|
function M.parser(plugSpec)
|
||||||
|
plugSpec.name = vim.split(plugSpec[1], '/')[2]
|
||||||
|
if not plugSpec.type or plugSpec.type == "none" then
|
||||||
|
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1]
|
||||||
|
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1]
|
||||||
|
plugSpec.url = "https://github.com/" .. plugSpec[1]
|
||||||
|
elseif plugSpec.type == "color" then
|
||||||
|
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1]
|
||||||
|
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/color'
|
||||||
|
plugSpec.repo = "https://github.com/" .. plugSpec[1]
|
||||||
|
elseif plugSpec.type == "plugin" then
|
||||||
|
plugSpec.rtp = config.bundle_dir .. "/" .. plugSpec[1]
|
||||||
|
plugSpec.path = config.bundle_dir .. "/" .. plugSpec[1] .. '/plugin'
|
||||||
|
plugSpec.url = "https://github.com/" .. plugSpec[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
return plugSpec
|
||||||
|
end
|
||||||
|
|
||||||
|
-- {'loadconf': 1,
|
||||||
|
-- 'type': 'none',
|
||||||
|
-- 'overwrite': 1,
|
||||||
|
-- 'lazy': 0,
|
||||||
|
-- 'name': 'defx-git',
|
||||||
|
-- 'rtp': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git',
|
||||||
|
-- 'normalized_name': 'defx-git',
|
||||||
|
-- 'local': 1,
|
||||||
|
-- 'sourced': 1,
|
||||||
|
-- 'orig_opts': {'repo': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git',
|
||||||
|
-- 'loadconf': 1,
|
||||||
|
-- 'type': 'none',
|
||||||
|
-- 'merged': 0,
|
||||||
|
-- 'hook_source': 'call SpaceVim#util#loadConfig(''plugins/defx-git.vim'')',
|
||||||
|
-- 'overwrite': 1},
|
||||||
|
-- 'repo': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git',
|
||||||
|
-- 'hook_source': 'call SpaceVim#util#loadConfig(''plugins/defx-git.vim'')',
|
||||||
|
-- 'called': {'''call SpaceVim#util#loadConfig(''''plugins/defx-git.vim'''')''': v:true},
|
||||||
|
-- 'merged': 0,
|
||||||
|
-- 'path': 'C:/Users/wsdjeg/.SpaceVim/bundle/defx-git'}
|
||||||
|
function M.load(plugSpec)
|
||||||
|
if vim.fn.isdirectory(plugSpec.rtp) == 1 then
|
||||||
|
vim.opt.runtimepath:append(plugSpec.rtp)
|
||||||
|
if vim.fn.has("vim_starting") ~= 1 then
|
||||||
|
local plugin_directory_files = vim.fn.globpath(plugSpec.rtp, "plugin/*.{lua,vim}")
|
||||||
|
for _, f in ipairs(plugin_directory_files) do
|
||||||
|
vim.cmd.source(f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
24
bundle/nvim-plug/plugin/plug.lua
vendored
Normal file
24
bundle/nvim-plug/plugin/plug.lua
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- plug.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("PlugInstall", function(opt)
|
||||||
|
local plugs = {}
|
||||||
|
local all_plugins = require('plug').get()
|
||||||
|
for _, v in ipairs(opt.fargs) do
|
||||||
|
local p = all_plugins[v]
|
||||||
|
if p then
|
||||||
|
table.insert(plugs, p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
require("plug.installer").install(plugs)
|
||||||
|
end, { nargs = "*", complete = function()
|
||||||
|
local plug_name = {}
|
||||||
|
for k, _ in pairs(require('plug').get()) do
|
||||||
|
table.insert(plug_name, k)
|
||||||
|
end
|
||||||
|
return plug_name
|
||||||
|
end })
|
31
bundle/nvim-plug/test/init.lua
vendored
Normal file
31
bundle/nvim-plug/test/init.lua
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
--=============================================================================
|
||||||
|
-- init.lua
|
||||||
|
-- Copyright 2025 Eric Wong
|
||||||
|
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||||
|
-- License: GPLv3
|
||||||
|
--=============================================================================
|
||||||
|
|
||||||
|
vim.opt.runtimepath:append('.')
|
||||||
|
vim.opt.runtimepath:append('~/.SpaceVim')
|
||||||
|
|
||||||
|
require('plug').setup({
|
||||||
|
|
||||||
|
bundle_dir = 'D:/bundle_dir',
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
require("plug").add({
|
||||||
|
{
|
||||||
|
"wsdjeg/scrollbar.vim",
|
||||||
|
events = { "VimEnter" },
|
||||||
|
config = function()
|
||||||
|
end
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wsdjeg/flygrep.nvim",
|
||||||
|
cmds = { "FlyGrep" },
|
||||||
|
config = function()
|
||||||
|
require('flygrep').setup()
|
||||||
|
end
|
||||||
|
},
|
||||||
|
})
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.__password = require('spacevim.api').import('password')
|
M.__password = require('spacevim.api.password')
|
||||||
|
|
||||||
local empty = function(expr)
|
local empty = function(expr)
|
||||||
return vim.fn.empty(expr) == 1
|
return vim.fn.empty(expr) == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user