mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-14 06:18:00 +08:00
feat(nvim-plug): support raw plugin
This commit is contained in:
parent
2fe9e8fc11
commit
68eaa0ec0f
353
bundle/nvim-plug/README.md
vendored
353
bundle/nvim-plug/README.md
vendored
@ -1,168 +1,185 @@
|
||||
# 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)
|
||||
|
||||
**Alpha version. Any changes, including backward incompatible changes, are applied without announcements.**
|
||||
|
||||
![Image](https://github.com/user-attachments/assets/93b04c48-4f41-46aa-b7f7-6390ee9622c7)
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
- [Plugin Spec](#plugin-spec)
|
||||
- [Commands](#commands)
|
||||
- [Default UI](#default-ui)
|
||||
- [Custom Plugin UI](#custom-plugin-ui)
|
||||
- [Feedback](#feedback)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Intro
|
||||
|
||||
nvim-plug is an asynchronous Neovim plugin manager written in Lua.
|
||||
|
||||
## Features
|
||||
|
||||
- **faster:** written in lua.
|
||||
- **async:** downloading and building via job.
|
||||
- **lazy loading:** lazy load plugin based on events, comamnd, mapping, etc..
|
||||
- **custom UI:** provide custom UI API.
|
||||
|
||||
## Usage
|
||||
|
||||
setup nvim-plug:
|
||||
|
||||
```lua
|
||||
require('plug').setup({
|
||||
bundle_dir = 'D:/bundle_dir',
|
||||
max_processes = 5, -- max number of processes used for nvim-plug job
|
||||
base_url = 'https://github.com',
|
||||
ui = 'notify', -- default ui is `notify`, use `default` for split window UI
|
||||
http_proxy = 'http://127.0.0.1:7890', -- default is nil
|
||||
https_proxy = 'http://127.0.0.1:7890', -- default is nil
|
||||
clone_depth = 1 -- default history depth for `git clone`
|
||||
})
|
||||
```
|
||||
|
||||
add plugins:
|
||||
|
||||
```lua
|
||||
|
||||
require('plug').add({
|
||||
{
|
||||
'wsdjeg/scrollbar.vim',
|
||||
events = { 'VimEnter' },
|
||||
config = function() end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/vim-chat',
|
||||
enabled = function()
|
||||
return vim.fn.has('nvim-0.10.0') == 1
|
||||
end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/flygrep.nvim',
|
||||
cmds = { 'FlyGrep' },
|
||||
config = function()
|
||||
require('flygrep').setup()
|
||||
end,
|
||||
},
|
||||
{
|
||||
'D:/wsdjeg/winbar.nvim',
|
||||
events = { 'VimEnter' },
|
||||
},
|
||||
{
|
||||
'wsdjeg/vim-mail',
|
||||
on_func = 'mail#',
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Plugin Spec
|
||||
|
||||
| name | description |
|
||||
| --------- | --------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `on_map` | `table<string>`, key bindings lazy loading |
|
||||
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
|
||||
| `frozen` | update only when specific with `PlugUpdate name` |
|
||||
| `depends` | `table<PluginSpec>` a list of plugins |
|
||||
|
||||
## Commands
|
||||
|
||||
- `:PlugInstall`: install specific plugin or all plugins
|
||||
- `:PlugUpdate`: update specific plugin or all plugins
|
||||
|
||||
## Default UI
|
||||
|
||||
The default is ui is inspired by [vundle](https://github.com/VundleVim/Vundle.vim)
|
||||
|
||||
The default highlight group.
|
||||
|
||||
| highlight group name | description |
|
||||
| -------------------- | ------------------------------- |
|
||||
| `PlugTitle` | the first line of plugin window |
|
||||
| `PlugProcess` | the process of downloading |
|
||||
| `PlugDone` | clone/build/install done |
|
||||
| `PlugFailed` | clone/build/install failed |
|
||||
| `PlugDoing` | job is running |
|
||||
|
||||
Default highlight link:
|
||||
|
||||
```lua
|
||||
vim.cmd('hi def link PlugTitle TODO')
|
||||
vim.cmd('hi def link PlugProcess Repeat')
|
||||
vim.cmd('hi def link PlugDone Type')
|
||||
vim.cmd('hi def link PlugFailed WarningMsg')
|
||||
vim.cmd('hi def link PlugDoing Number')
|
||||
```
|
||||
|
||||
## Custom Plugin UI
|
||||
|
||||
To setup custom UI, you need to creat a on_update function, this function is called with two arges, `name` and `plugUiData`.
|
||||
|
||||
The plugUiData is table with following keys:
|
||||
|
||||
| key | description |
|
||||
| --------------- | ---------------------------------------------------- |
|
||||
| `clone_done` | boolead, is true when clone successfully |
|
||||
| `command` | string, clone, pull or build |
|
||||
| `clone_process` | string, git clone progress, such as `16% (160/1000)` |
|
||||
| `clone_done` | boolean, git clone exit status |
|
||||
| `building` | boolean |
|
||||
| `build_done` | boolean |
|
||||
| `pull_done` | boolean |
|
||||
| `pull_process` | string |
|
||||
|
||||
```lua
|
||||
--- your custom UI
|
||||
|
||||
local function on_ui_update(name, data)
|
||||
-- logic
|
||||
end
|
||||
|
||||
|
||||
require('plug').setup({
|
||||
bundle_dir = 'D:/bundle_dir',
|
||||
max_processes = 5, -- max number of processes used for nvim-plug job
|
||||
base_url = 'https://github.com',
|
||||
ui = on_ui_update, -- default ui is notify, use `default` for split window UI
|
||||
})
|
||||
```
|
||||
|
||||
## 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) or [Telegram group](https://t.me/+w27TxYbUz1wxZmJl)
|
||||
# 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)
|
||||
|
||||
**Alpha version. Any changes, including backward incompatible changes, are applied without announcements.**
|
||||
|
||||
![Image](https://github.com/user-attachments/assets/93b04c48-4f41-46aa-b7f7-6390ee9622c7)
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
- [Plugin Spec](#plugin-spec)
|
||||
- [Commands](#commands)
|
||||
- [Default UI](#default-ui)
|
||||
- [Custom Plugin UI](#custom-plugin-ui)
|
||||
- [Feedback](#feedback)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Intro
|
||||
|
||||
nvim-plug is an asynchronous Neovim plugin manager written in Lua.
|
||||
|
||||
## Features
|
||||
|
||||
- **faster:** written in lua.
|
||||
- **async:** downloading and building via job.
|
||||
- **lazy loading:** lazy load plugin based on events, comamnd, mapping, etc..
|
||||
- **custom UI:** provide custom UI API.
|
||||
|
||||
## Usage
|
||||
|
||||
setup nvim-plug:
|
||||
|
||||
```lua
|
||||
require('plug').setup({
|
||||
-- set the bundle dir
|
||||
bundle_dir = 'D:/bundle_dir',
|
||||
-- set the path where raw plugin is download to
|
||||
raw_plugin_dir = 'D:/bundle_dir/raw_plugin',
|
||||
-- max number of processes used for nvim-plug job
|
||||
max_processes = 5,
|
||||
base_url = 'https://github.com',
|
||||
-- default ui is `notify`, use `default` for split window UI
|
||||
ui = 'notify',
|
||||
-- default is nil
|
||||
http_proxy = 'http://127.0.0.1:7890',
|
||||
-- default is nil
|
||||
https_proxy = 'http://127.0.0.1:7890',
|
||||
-- default history depth for `git clone`
|
||||
clone_depth = 1,
|
||||
})
|
||||
```
|
||||
|
||||
add plugins:
|
||||
|
||||
```lua
|
||||
require('plug').add({
|
||||
{
|
||||
'wsdjeg/scrollbar.vim',
|
||||
events = { 'VimEnter' },
|
||||
config = function() end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/vim-chat',
|
||||
enabled = function()
|
||||
return vim.fn.has('nvim-0.10.0') == 1
|
||||
end,
|
||||
},
|
||||
{
|
||||
'wsdjeg/flygrep.nvim',
|
||||
cmds = { 'FlyGrep' },
|
||||
config = function()
|
||||
require('flygrep').setup()
|
||||
end,
|
||||
},
|
||||
{
|
||||
type = 'raw',
|
||||
url = 'https://gist.githubusercontent.com/wsdjeg/4ac99019c5ca156d35704550648ba321/raw/4e8c202c74e98b5d56616c784bfbf9b873dc8868/markdown.vim',
|
||||
script_type = 'after/syntax'
|
||||
},
|
||||
{
|
||||
'D:/wsdjeg/winbar.nvim',
|
||||
events = { 'VimEnter' },
|
||||
},
|
||||
{
|
||||
'wsdjeg/vim-mail',
|
||||
on_func = 'mail#',
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Plugin Spec
|
||||
|
||||
The plugin spec is inspired by dein.nvim.
|
||||
|
||||
| name | description |
|
||||
| ------------- | ---------------------------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `on_map` | `table<string>`, key bindings lazy loading |
|
||||
| `on_func` | `string` or `table<string>`, vim function lazy loading |
|
||||
| `script_type` | `string`, plugin type including `color`, `plugin`, etc.. |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
| `enabled` | `boolean` or `function` evaluated when startup, when it is false, plugin will be skiped |
|
||||
| `frozen` | update only when specific with `PlugUpdate name` |
|
||||
| `depends` | `table<PluginSpec>` a list of plugins |
|
||||
| `branch` | `string` specific git branch |
|
||||
| `tag` | `string` specific git tag |
|
||||
| `type` | `string` specific plugin type, this can be git, raw or none, if it is raw, `script_type` must be set |
|
||||
|
||||
## Commands
|
||||
|
||||
- `:PlugInstall`: install specific plugin or all plugins
|
||||
- `:PlugUpdate`: update specific plugin or all plugins
|
||||
|
||||
## Default UI
|
||||
|
||||
The default is ui is inspired by [vundle](https://github.com/VundleVim/Vundle.vim)
|
||||
|
||||
The default highlight group.
|
||||
|
||||
| highlight group name | description |
|
||||
| -------------------- | ------------------------------- |
|
||||
| `PlugTitle` | the first line of plugin window |
|
||||
| `PlugProcess` | the process of downloading |
|
||||
| `PlugDone` | clone/build/install done |
|
||||
| `PlugFailed` | clone/build/install failed |
|
||||
| `PlugDoing` | job is running |
|
||||
|
||||
Default highlight link:
|
||||
|
||||
```lua
|
||||
vim.cmd('hi def link PlugTitle TODO')
|
||||
vim.cmd('hi def link PlugProcess Repeat')
|
||||
vim.cmd('hi def link PlugDone Type')
|
||||
vim.cmd('hi def link PlugFailed WarningMsg')
|
||||
vim.cmd('hi def link PlugDoing Number')
|
||||
```
|
||||
|
||||
## Custom Plugin UI
|
||||
|
||||
To setup custom UI, you need to creat a on_update function, this function is called with two arges, `name` and `plugUiData`.
|
||||
|
||||
The plugUiData is table with following keys:
|
||||
|
||||
| key | description |
|
||||
| --------------- | ---------------------------------------------------- |
|
||||
| `clone_done` | boolead, is true when clone successfully |
|
||||
| `command` | string, clone, pull or build |
|
||||
| `clone_process` | string, git clone progress, such as `16% (160/1000)` |
|
||||
| `clone_done` | boolean, git clone exit status |
|
||||
| `building` | boolean |
|
||||
| `build_done` | boolean |
|
||||
| `pull_done` | boolean |
|
||||
| `pull_process` | string |
|
||||
|
||||
```lua
|
||||
--- your custom UI
|
||||
|
||||
local function on_ui_update(name, data)
|
||||
-- logic
|
||||
end
|
||||
|
||||
|
||||
require('plug').setup({
|
||||
bundle_dir = 'D:/bundle_dir',
|
||||
max_processes = 5, -- max number of processes used for nvim-plug job
|
||||
base_url = 'https://github.com',
|
||||
ui = on_ui_update, -- default ui is notify, use `default` for split window UI
|
||||
})
|
||||
```
|
||||
|
||||
## 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) or [Telegram group](https://t.me/+w27TxYbUz1wxZmJl)
|
||||
|
1
bundle/nvim-plug/lua/plug/config.lua
vendored
1
bundle/nvim-plug/lua/plug/config.lua
vendored
@ -8,6 +8,7 @@
|
||||
local M = {}
|
||||
|
||||
M.bundle_dir = vim.fn.stdpath('data') .. '/bundle_dir'
|
||||
M.raw_plugin_dir = vim.fn.stdpath('data') .. '/bundle_dir/raw_plugin'
|
||||
M.max_processes = 5
|
||||
M.base_url = 'https://github.com/'
|
||||
M.ui = 'notify'
|
||||
|
74
bundle/nvim-plug/lua/plug/installer.lua
vendored
74
bundle/nvim-plug/lua/plug/installer.lua
vendored
@ -7,6 +7,8 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
local H = {}
|
||||
|
||||
local job = require('spacevim.api.job')
|
||||
local notify = require('spacevim.api.notify')
|
||||
local jobs = {}
|
||||
@ -34,9 +36,10 @@ local processes = 0
|
||||
local installation_queue = {}
|
||||
local building_queue = {}
|
||||
local updating_queue = {}
|
||||
local raw_download_queue = {}
|
||||
|
||||
--- @param plugSpec PluginSpec
|
||||
local function build(plugSpec)
|
||||
function H.build(plugSpec)
|
||||
if processes >= config.max_processes then
|
||||
table.insert(building_queue, plugSpec)
|
||||
return
|
||||
@ -61,7 +64,7 @@ local function build(plugSpec)
|
||||
end
|
||||
processes = processes - 1
|
||||
if #building_queue > 0 then
|
||||
build(table.remove(building_queue))
|
||||
H.build(table.remove(building_queue))
|
||||
end
|
||||
end,
|
||||
cwd = plugSpec.path,
|
||||
@ -75,7 +78,44 @@ local function build(plugSpec)
|
||||
end
|
||||
|
||||
--- @param plugSpec PluginSpec
|
||||
local function install_plugin(plugSpec)
|
||||
function H.download_raw(plugSpec, force)
|
||||
if processes >= config.max_processes then
|
||||
table.insert(raw_download_queue, plugSpec)
|
||||
return
|
||||
elseif vim.fn.filereadable(plugSpec.path) == 1 and not force then
|
||||
on_uidate(plugSpec.name, { command = 'curl', curl_done = true })
|
||||
return
|
||||
end
|
||||
|
||||
local cmd = {'curl', '-fLo', plugSpec.path, '--create-dirs', plugSpec.url}
|
||||
on_uidate(plugSpec.name, { command = 'curl'})
|
||||
local jobid = job.start(cmd, {
|
||||
on_exit = function(id, data, single)
|
||||
if data == 0 and single == 0 then
|
||||
on_uidate(plugSpec.name, { curl_done = true })
|
||||
else
|
||||
on_uidate(plugSpec.name, { curl_done = false })
|
||||
end
|
||||
processes = processes - 1
|
||||
if #installation_queue > 0 then
|
||||
H.install_plugin(table.remove(installation_queue, 1))
|
||||
elseif #building_queue > 0 then
|
||||
H.build(table.remove(building_queue, 1))
|
||||
end
|
||||
end,
|
||||
env = {
|
||||
http_proxy = config.http_proxy,
|
||||
https_proxy = config.https_proxy,
|
||||
},
|
||||
})
|
||||
processes = processes + 1
|
||||
jobs['jobid_' .. jobid] = plugSpec.name
|
||||
|
||||
|
||||
end
|
||||
|
||||
--- @param plugSpec PluginSpec
|
||||
function H.install_plugin(plugSpec)
|
||||
if processes >= config.max_processes then
|
||||
table.insert(installation_queue, plugSpec)
|
||||
return
|
||||
@ -113,16 +153,16 @@ local function install_plugin(plugSpec)
|
||||
if data == 0 and single == 0 then
|
||||
on_uidate(plugSpec.name, { clone_done = true, download_process = 100 })
|
||||
if plugSpec.build then
|
||||
build(plugSpec)
|
||||
H.build(plugSpec)
|
||||
end
|
||||
else
|
||||
on_uidate(plugSpec.name, { clone_done = false, download_process = 0 })
|
||||
end
|
||||
processes = processes - 1
|
||||
if #installation_queue > 0 then
|
||||
install_plugin(table.remove(installation_queue, 1))
|
||||
H.install_plugin(table.remove(installation_queue, 1))
|
||||
elseif #building_queue > 0 then
|
||||
build(table.remove(building_queue, 1))
|
||||
H.build(table.remove(building_queue, 1))
|
||||
end
|
||||
end,
|
||||
env = {
|
||||
@ -135,9 +175,9 @@ local function install_plugin(plugSpec)
|
||||
end
|
||||
|
||||
--- @param plugSpec PluginSpec
|
||||
local function update_plugin(plugSpec, force)
|
||||
function H.update_plugin(plugSpec, force)
|
||||
if processes >= config.max_processes then
|
||||
table.insert(updating_queue, {plugSpec, force})
|
||||
table.insert(updating_queue, { plugSpec, force })
|
||||
return
|
||||
elseif vim.fn.isdirectory(plugSpec.path) ~= 1 then
|
||||
-- if the directory does not exist, return failed
|
||||
@ -162,16 +202,16 @@ local function update_plugin(plugSpec, force)
|
||||
if data == 0 and single == 0 then
|
||||
on_uidate(plugSpec.name, { pull_done = true })
|
||||
if plugSpec.build then
|
||||
build(plugSpec)
|
||||
H.build(plugSpec)
|
||||
end
|
||||
else
|
||||
on_uidate(plugSpec.name, { pull_done = false })
|
||||
end
|
||||
processes = processes - 1
|
||||
if #updating_queue > 0 then
|
||||
update_plugin(unpack(table.remove(updating_queue, 1)))
|
||||
H.update_plugin(unpack(table.remove(updating_queue, 1)))
|
||||
elseif #building_queue > 0 then
|
||||
build(table.remove(building_queue, 1))
|
||||
H.build(table.remove(building_queue, 1))
|
||||
end
|
||||
end,
|
||||
cwd = plugSpec.path,
|
||||
@ -190,13 +230,21 @@ end
|
||||
|
||||
M.install = function(plugSpecs)
|
||||
for _, v in ipairs(plugSpecs) do
|
||||
install_plugin(v)
|
||||
if v.type == 'raw' then
|
||||
H.download_raw(v)
|
||||
else
|
||||
H.install_plugin(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.update = function(plugSpecs, force)
|
||||
for _, v in ipairs(plugSpecs) do
|
||||
update_plugin(v, force)
|
||||
if v.type == 'raw' then
|
||||
H.download_raw(v, force)
|
||||
else
|
||||
H.update_plugin(v, force)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
225
bundle/nvim-plug/lua/plug/loader.lua
vendored
225
bundle/nvim-plug/lua/plug/loader.lua
vendored
@ -1,102 +1,123 @@
|
||||
--=============================================================================
|
||||
-- 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
|
||||
--- @field name string
|
||||
--- @field branch string
|
||||
--- @field tag string
|
||||
--- @field url string
|
||||
--- @field path string
|
||||
--- @field build string|table<string>
|
||||
--- @field is_local boolean true for local plugin
|
||||
--- @field when boolean|string|function
|
||||
--- @field frozen boolean
|
||||
|
||||
local function is_local_plugin(plugSpec)
|
||||
if plugSpec.is_local or vim.fn.isdirectory(plugSpec[1]) == 1 then
|
||||
plugSpec.is_local = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function unique_name(plugSpec)
|
||||
local s = vim.split(plugSpec[1], '/')
|
||||
return s[#s]
|
||||
end
|
||||
|
||||
function M.parser(plugSpec)
|
||||
if type(plugSpec.enabled) == "nil" then
|
||||
plugSpec.enabled = true
|
||||
elseif type(plugSpec.enabled) == "function" then
|
||||
plugSpec.enabled = plugSpec.enabled()
|
||||
elseif type(plugSpec.enabled) ~= "boolean" or plugSpec.enabled == false then
|
||||
plugSpec.enabled = false
|
||||
return plugSpec
|
||||
end
|
||||
plugSpec.name = unique_name(plugSpec)
|
||||
if is_local_plugin(plugSpec) then
|
||||
plugSpec.rtp = plugSpec[1]
|
||||
plugSpec.path = plugSpec[1]
|
||||
plugSpec.url = nil
|
||||
elseif not plugSpec.type or plugSpec.type == 'none' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.url = config.base_url .. '/' .. plugSpec[1]
|
||||
elseif plugSpec.type == 'color' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/color'
|
||||
plugSpec.repo = config.base_url .. '/' .. plugSpec[1]
|
||||
elseif plugSpec.type == 'plugin' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/plugin'
|
||||
plugSpec.url = config.base_url .. '/' .. 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}", 0, 1)
|
||||
for _, f in ipairs(plugin_directory_files) do
|
||||
vim.cmd.source(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
--=============================================================================
|
||||
-- loader.lua
|
||||
-- Copyright 2025 Eric Wong
|
||||
-- Author: Eric Wong < wsdjeg@outlook.com >
|
||||
-- License: GPLv3
|
||||
--=============================================================================
|
||||
|
||||
local M = {}
|
||||
|
||||
local config = require('plug.config')
|
||||
|
||||
local add_raw_rtp = false
|
||||
|
||||
--- @class PluginSpec
|
||||
--- @field rtp string
|
||||
--- @field events table<string>
|
||||
--- @field cmds table<string>
|
||||
--- @field config function
|
||||
--- @field name string
|
||||
--- @field branch string
|
||||
--- @field tag string
|
||||
--- @field url string
|
||||
--- @field path string
|
||||
--- @field build string|table<string>
|
||||
--- @field is_local boolean true for local plugin
|
||||
--- @field when boolean|string|function
|
||||
--- @field frozen boolean
|
||||
--- @field type string "git", "raw" or "none"
|
||||
--- @field script_type string "git", "raw" or "none"
|
||||
|
||||
local function is_local_plugin(plugSpec)
|
||||
if plugSpec.is_local or vim.fn.isdirectory(plugSpec[1]) == 1 then
|
||||
plugSpec.is_local = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function check_name(plugSpec)
|
||||
if not plugSpec[1] and not plugSpec.url then
|
||||
return false
|
||||
end
|
||||
local s = vim.split(plugSpec[1] or plugSpec.url, '/')
|
||||
plugSpec.name = s[#s]
|
||||
return true
|
||||
end
|
||||
|
||||
function M.parser(plugSpec)
|
||||
if type(plugSpec.enabled) == 'nil' then
|
||||
plugSpec.enabled = true
|
||||
elseif type(plugSpec.enabled) == 'function' then
|
||||
plugSpec.enabled = plugSpec.enabled()
|
||||
elseif type(plugSpec.enabled) ~= 'boolean' or plugSpec.enabled == false then
|
||||
plugSpec.enabled = false
|
||||
return plugSpec
|
||||
elseif not check_name(plugSpec) then
|
||||
plugSpec.enabled = false
|
||||
return plugSpec
|
||||
end
|
||||
if is_local_plugin(plugSpec) then
|
||||
plugSpec.rtp = plugSpec[1]
|
||||
plugSpec.path = plugSpec[1]
|
||||
plugSpec.url = nil
|
||||
elseif plugSpec.type == 'raw' then
|
||||
if not plugSpec.script_type or plugSpec.script_type == 'none' then
|
||||
plugSpec.enabled = false
|
||||
return plugSpec
|
||||
else
|
||||
plugSpec.path = config.raw_plugin_dir .. '/' .. plugSpec.script_type .. plugSpec.name
|
||||
if not add_raw_rtp then
|
||||
vim.opt:append(config.raw_plugin_dir)
|
||||
add_raw_rtp = true
|
||||
end
|
||||
end
|
||||
elseif not plugSpec.script_type or plugSpec.script_type == 'none' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.url = config.base_url .. '/' .. plugSpec[1]
|
||||
elseif plugSpec.script_type == 'color' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/color'
|
||||
plugSpec.repo = config.base_url .. '/' .. plugSpec[1]
|
||||
elseif plugSpec.script_type == 'plugin' then
|
||||
plugSpec.rtp = config.bundle_dir .. '/' .. plugSpec[1]
|
||||
plugSpec.path = config.bundle_dir .. '/' .. plugSpec[1] .. '/plugin'
|
||||
plugSpec.url = config.base_url .. '/' .. 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 plugSpec.rtp and 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}', 0, 1)
|
||||
for _, f in ipairs(plugin_directory_files) do
|
||||
vim.cmd.source(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
8
bundle/nvim-plug/lua/plug/ui.lua
vendored
8
bundle/nvim-plug/lua/plug/ui.lua
vendored
@ -72,6 +72,14 @@ local function build_context()
|
||||
else
|
||||
table.insert(b, '- ' .. k)
|
||||
end
|
||||
elseif plug.command == 'curl' then
|
||||
if plug.curl_done then
|
||||
table.insert(b, '√ ' .. k .. ' download')
|
||||
elseif plug.curl_done == false then
|
||||
table.insert(b, '× ' .. k .. ' failed to download')
|
||||
else
|
||||
table.insert(b, '- ' .. k .. string.format(' downloading'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
6
bundle/nvim-plug/test/init.lua
vendored
6
bundle/nvim-plug/test/init.lua
vendored
@ -11,6 +11,7 @@ vim.opt.runtimepath:append('~/.SpaceVim')
|
||||
require('plug').setup({
|
||||
|
||||
bundle_dir = 'D:/bundle_dir',
|
||||
raw_plugin_dir = 'D:/bundle_dir/raw_plugin',
|
||||
ui = 'default',
|
||||
http_proxy = 'http://127.0.0.1:7890',
|
||||
https_proxy = 'http://127.0.0.1:7890',
|
||||
@ -21,6 +22,11 @@ require('plug').add({
|
||||
'wsdjeg/SourceCounter.vim',
|
||||
cmds = { 'SourceCounter' },
|
||||
},
|
||||
{
|
||||
type = 'raw',
|
||||
url = 'https://gist.githubusercontent.com/wsdjeg/4ac99019c5ca156d35704550648ba321/raw/4e8c202c74e98b5d56616c784bfbf9b873dc8868/markdown.vim',
|
||||
script_type = 'after/syntax'
|
||||
},
|
||||
{
|
||||
'wsdjeg/git.vim',
|
||||
cmds = { 'Git' },
|
||||
|
Loading…
Reference in New Issue
Block a user