| 1 |
local M = {}
|
| 2 |
local plug_dir = vim.fn.stdpath("data") .. "/plugins"
|
| 3 |
|
| 4 |
local function ensure(spec)
|
| 5 |
local repo = type(spec) == "string" and spec or spec[1]
|
| 6 |
local name = repo:match(".+/(.+)$")
|
| 7 |
local path = plug_dir .. "/" .. name
|
| 8 |
|
| 9 |
if not vim.uv.fs_stat(path) then
|
| 10 |
vim.fn.mkdir(plug_dir, "p")
|
| 11 |
local cmd = { "git", "clone", "--depth=1" }
|
| 12 |
if spec.branch then
|
| 13 |
table.insert(cmd, "-b")
|
| 14 |
table.insert(cmd, spec.branch)
|
| 15 |
end
|
| 16 |
table.insert(cmd, "https://github.com/" .. repo)
|
| 17 |
table.insert(cmd, path)
|
| 18 |
print("Installing " .. name .. "...")
|
| 19 |
vim.fn.system(cmd)
|
| 20 |
end
|
| 21 |
|
| 22 |
vim.opt.rtp:append(path)
|
| 23 |
local lua_path = path .. "/lua"
|
| 24 |
if vim.uv.fs_stat(lua_path) then
|
| 25 |
package.path = package.path .. ";" .. lua_path .. "/?.lua;" .. lua_path .. "/?/init.lua"
|
| 26 |
end
|
| 27 |
end
|
| 28 |
|
| 29 |
function M.setup()
|
| 30 |
for _, spec in ipairs(require("plugin-list")) do
|
| 31 |
ensure(spec)
|
| 32 |
end
|
| 33 |
end
|
| 34 |
|
| 35 |
return M
|