From a842704063c0575345a57b621ff7618a26116235 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 5 Feb 2025 00:55:49 +0800 Subject: [PATCH] feat(nvim-plug): support local plugins --- bundle/nvim-plug/lua/plug/installer.lua | 3 +++ bundle/nvim-plug/lua/plug/loader.lua | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bundle/nvim-plug/lua/plug/installer.lua b/bundle/nvim-plug/lua/plug/installer.lua index 4faed1e34..cbf879954 100644 --- a/bundle/nvim-plug/lua/plug/installer.lua +++ b/bundle/nvim-plug/lua/plug/installer.lua @@ -55,6 +55,9 @@ local function install_plugin(plugSpec) if processes >= config.max_processes then table.insert(installation_queue, plugSpec) return + elseif vim.fn.isdirectory(plugSpec.path) == 1 then + -- if the directory exists, skip installation + return end local cmd = { 'git', 'clone', '--depth', '1' } if plugSpec.branch then diff --git a/bundle/nvim-plug/lua/plug/loader.lua b/bundle/nvim-plug/lua/plug/loader.lua index 2ccc9aae8..0a8dcc2e7 100644 --- a/bundle/nvim-plug/lua/plug/loader.lua +++ b/bundle/nvim-plug/lua/plug/loader.lua @@ -20,10 +20,27 @@ local config = require('plug.config') --- @field url string --- @field path string --- @field build string|table +--- @field is_local boolean true for local plugin + +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, '/') + return s[#s] +end function M.parser(plugSpec) - plugSpec.name = vim.split(plugSpec[1], '/')[2] - if not plugSpec.type or plugSpec.type == 'none' then + 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]