-
Notifications
You must be signed in to change notification settings - Fork 2
/
packages.lua
196 lines (183 loc) · 5.24 KB
/
packages.lua
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
if vim.env.NVIM_NO3RD then
return
end
local utils = require('utils')
local icons = utils.static.icons
local conf_path = vim.fn.stdpath('config') --[[@as string]]
local data_path = vim.fn.stdpath('data') --[[@as string]]
local state_path = vim.fn.stdpath('state') --[[@as string]]
---Install package manager if not already installed
---@return boolean success
local function bootstrap()
vim.g.package_path = vim.fs.joinpath(data_path, 'packages')
vim.g.package_lock = vim.fs.joinpath(conf_path, 'package-lock.json')
local lazy_path = vim.fs.joinpath(vim.g.package_path, 'lazy.nvim')
if vim.uv.fs_stat(lazy_path) then
vim.opt.rtp:prepend(lazy_path)
return true
end
local startup_file = vim.fs.joinpath(state_path, 'startup.json')
local startup_data = utils.json.read(startup_file)
if startup_data.bootstrap == false then
return false
end
local response = ''
vim.ui.input({
prompt = '[packages] package manager not found, bootstrap? [y/N/never] ',
}, function(r)
response = r
end)
if vim.fn.match(response, '[Nn][Ee][Vv][Ee][Rr]') >= 0 then
startup_data.bootstrap = false
utils.json.write(startup_file, startup_data)
return false
end
if vim.fn.match(response, '^[Yy]\\([Ee][Ss]\\)\\?$') < 0 then
return false
end
print('\n')
local lock_data = utils.json.read(vim.g.package_lock)
local commit = lock_data['lazy.nvim'] and lock_data['lazy.nvim'].commit
local url = 'https://github.com/folke/lazy.nvim.git'
vim.notify('[packages] installing lazy.nvim...')
vim.fn.mkdir(vim.g.package_path, 'p')
if
not utils.git.execute({
'clone',
'--filter=blob:none',
url,
lazy_path,
}, vim.log.levels.INFO).success
then
return false
end
if commit then
utils.git.dir_execute(
lazy_path,
{ 'checkout', commit },
vim.log.levels.INFO
)
end
local lazy_patch_path =
vim.fs.joinpath(conf_path, 'patches', 'lazy.nvim.patch')
if vim.uv.fs_stat(lazy_patch_path) and vim.uv.fs_stat(lazy_path) then
utils.git.dir_execute(lazy_path, {
'apply',
'--ignore-space-change',
lazy_patch_path,
}, vim.log.levels.WARN)
end
vim.notify('[packages] lazy.nvim cloned to ' .. lazy_path)
vim.opt.rtp:prepend(lazy_path)
return true
end
---Enable modules
---@param module_names string[]
local function enable_modules(module_names)
local config = {
root = vim.g.package_path,
lockfile = vim.g.package_lock,
ui = {
border = vim.g.modern_ui and 'solid' or 'single',
size = { width = 0.7, height = 0.74 },
icons = {
cmd = icons.Cmd,
config = icons.Config,
event = icons.Event,
debug = '',
favorite = icons.star,
ft = icons.File,
init = icons.Config,
import = icons.ArrowLeft,
keys = icons.Keyboard,
lazy = icons.Lazy,
loaded = icons.CircleFilled,
not_loaded = icons.CircleOutline,
plugin = icons.Module,
runtime = icons.File,
require = icons.Lua,
source = icons.Method,
start = icons.Play,
task = icons.Ok,
list = { '' },
},
},
checker = { enabled = false },
change_detection = { notify = false },
install = { colorscheme = { 'macro', 'nano', 'cockatoo' } },
}
local modules = {}
for _, module_name in ipairs(module_names) do
vim.list_extend(modules, require('modules.' .. module_name))
end
require('lazy').setup(modules, config)
end
if not bootstrap() then
return
end
-- Reverse/Apply local patches on updating/intalling plugins,
-- must be created before setting lazy to apply the patches properly
vim.api.nvim_create_autocmd('User', {
desc = 'Reverse/Apply local patches on updating/intalling plugins.',
group = vim.api.nvim_create_augroup('LazyPatches', {}),
pattern = {
'LazyInstall*',
'LazyUpdate*',
'LazySync*',
'LazyRestore*',
},
callback = function(info)
-- In a lazy sync action:
-- -> LazySyncPre <- restore packages
-- -> LazyInstallPre
-- -> LazyUpdatePre
-- -> LazyInstall
-- -> LazyUpdate
-- -> LazySync <- apply patches
vim.g._lz_syncing = vim.g._lz_syncing or info.match == 'LazySyncPre'
if vim.g._lz_syncing and not info.match:find('^LazySync') then
return
end
if info.match == 'LazySync' then
vim.g._lz_syncing = nil
end
local patches_path = vim.fs.joinpath(conf_path, 'patches')
for patch in vim.fs.dir(patches_path) do
local patch_path = vim.fs.joinpath(patches_path, patch)
local plugin_path =
vim.fs.joinpath(vim.g.package_path, (patch:gsub('%.patch$', '')))
if vim.uv.fs_stat(plugin_path) then
utils.git.dir_execute(plugin_path, {
'restore',
'.',
})
if not info.match:find('Pre$') then
vim.notify('[packages] applying patch ' .. patch)
utils.git.dir_execute(plugin_path, {
'apply',
'--ignore-space-change',
patch_path,
}, vim.log.levels.WARN)
end
end
end
end,
})
if vim.g.vscode then
enable_modules({
'lib',
'edit',
'treesitter',
})
else
enable_modules({
'lib',
'edit',
'debug',
'tools',
'markup',
'completion',
'treesitter',
'colorschemes',
})
end