diff --git a/.ci/detach_plugin.sh b/.ci/detach_plugin.sh index f522233eb..65d28c46c 100755 --- a/.ci/detach_plugin.sh +++ b/.ci/detach_plugin.sh @@ -136,6 +136,26 @@ main () { _detact_bundle dein-ui.vim README.md _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) git clone https://github.com/wsdjeg/format.nvim.git detach/$1 cd detach/$1 diff --git a/bundle/nvim-plug/README.md b/bundle/nvim-plug/README.md new file mode 100644 index 000000000..14f4d399a --- /dev/null +++ b/bundle/nvim-plug/README.md @@ -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`, 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) diff --git a/bundle/nvim-plug/lua/plug/config.lua b/bundle/nvim-plug/lua/plug/config.lua new file mode 100644 index 000000000..25140dab4 --- /dev/null +++ b/bundle/nvim-plug/lua/plug/config.lua @@ -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 diff --git a/bundle/nvim-plug/lua/plug/hooks.lua b/bundle/nvim-plug/lua/plug/hooks.lua new file mode 100644 index 000000000..1fc965409 --- /dev/null +++ b/bundle/nvim-plug/lua/plug/hooks.lua @@ -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 +--- @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 diff --git a/bundle/nvim-plug/lua/plug/init.lua b/bundle/nvim-plug/lua/plug/init.lua new file mode 100644 index 000000000..340365e0c --- /dev/null +++ b/bundle/nvim-plug/lua/plug/init.lua @@ -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 +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 diff --git a/bundle/nvim-plug/lua/plug/installer.lua b/bundle/nvim-plug/lua/plug/installer.lua new file mode 100644 index 000000000..be0a3fb46 --- /dev/null +++ b/bundle/nvim-plug/lua/plug/installer.lua @@ -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 diff --git a/bundle/nvim-plug/lua/plug/loader.lua b/bundle/nvim-plug/lua/plug/loader.lua new file mode 100644 index 000000000..f73e9d318 --- /dev/null +++ b/bundle/nvim-plug/lua/plug/loader.lua @@ -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 +--- @field cmds table +--- @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 diff --git a/bundle/nvim-plug/plugin/plug.lua b/bundle/nvim-plug/plugin/plug.lua new file mode 100644 index 000000000..8000d9e46 --- /dev/null +++ b/bundle/nvim-plug/plugin/plug.lua @@ -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 }) diff --git a/bundle/nvim-plug/test/init.lua b/bundle/nvim-plug/test/init.lua new file mode 100644 index 000000000..d143c4a88 --- /dev/null +++ b/bundle/nvim-plug/test/init.lua @@ -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 + }, +}) diff --git a/lua/spacevim/api/notify.lua b/lua/spacevim/api/notify.lua index b0c5599a4..2846c1cff 100644 --- a/lua/spacevim/api/notify.lua +++ b/lua/spacevim/api/notify.lua @@ -8,7 +8,7 @@ local M = {} -M.__password = require('spacevim.api').import('password') +M.__password = require('spacevim.api.password') local empty = function(expr) return vim.fn.empty(expr) == 1