-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
110 lines (96 loc) · 3.03 KB
/
Copy pathinit.lua
File metadata and controls
110 lines (96 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
-- [[ vim.loader ]]
vim.loader.enable()
-- [[ GLOBALS ]]
-- Leader key
-- WARNING: Required before loading plugins
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Requires a Nerd Font
vim.g.have_nerd_font = true
-- Disable unused providers to speed up startup and clear warnings
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
vim.g.loaded_ruby_provider = 0
-- [[ CONFIGURATIONS ]]
require("config.options")
require("config.keymaps")
require("config.autocommands")
require("config.autoreload").setup()
-- [[ PLUGINS ]]
-- Using Neovim's native package manager (pack)
local pack_path = vim.fn.stdpath("data") .. "/site/pack/plugins/start"
local function bootstrap_pack(plugins_list)
local github_prefix = "https://github.com/"
for _, plugin in ipairs(plugins_list) do
local repo, name, url, branch
if type(plugin) == "string" then
repo = plugin
name = plugin:match(".*/(.*)")
url = github_prefix .. repo .. ".git"
elseif type(plugin) == "table" then
repo = plugin[1]
name = plugin.name or repo:match(".*/(.*)")
url = plugin.url or (github_prefix .. repo .. ".git")
branch = plugin.branch or plugin.tag
end
local install_path = pack_path .. "/" .. name
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.api.nvim_echo({ { "Cloning " .. (repo or name) .. "...", "Type" } }, true, {})
local clone_cmd = {
"git",
"clone",
"--filter=blob:none",
}
if branch then
table.insert(clone_cmd, "--branch")
table.insert(clone_cmd, branch)
end
table.insert(clone_cmd, url)
table.insert(clone_cmd, install_path)
vim.fn.system(clone_cmd)
end
-- Load the plugin instantly into Neovim's runtimepath
vim.opt.runtimepath:prepend(install_path)
end
end
-- Load dynamically discovered plugin configuration definitions
local custom_plugins = require("custom.plugins")
-- Clone plugins and inject into runtimepath
bootstrap_pack(custom_plugins.plugins)
-- Automatically clean up plugins that are no longer in the configuration list
local function cleanup_unused_plugins(plugins_list)
local active_names = {}
for _, plugin in ipairs(plugins_list) do
local name
if type(plugin) == "string" then
name = plugin:match(".*/(.*)")
elseif type(plugin) == "table" then
name = plugin.name or plugin[1]:match(".*/(.*)")
end
if name then
active_names[name] = true
end
end
local handle = vim.uv.fs_scandir(pack_path)
if handle then
while true do
local name, fs_type = vim.uv.fs_scandir_next(handle)
if not name then
break
end
if fs_type == "directory" and not active_names[name] then
local dir_to_delete = pack_path .. "/" .. name
vim.api.nvim_echo({ { "Removing unused plugin: " .. name .. "\n", "WarningMsg" } }, true, {})
vim.fn.delete(dir_to_delete, "rf")
end
end
end
end
cleanup_unused_plugins(custom_plugins.plugins)
-- Execute each plugin's setup config
for _, config_fn in ipairs(custom_plugins.configs) do
local ok, err = pcall(config_fn)
if not ok then
vim.notify("Error configuring plugin: " .. tostring(err), vim.log.levels.ERROR)
end
end