-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plug.lua
1549 lines (1318 loc) · 35.5 KB
/
plug.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
------------------------------------------
-- this file is automatically generated --
-- do not edit directly --
------------------------------------------
local build_checksum = "2ca5a81bcd384910938f6484036bd04451edfaebaaa0bb20747ab21c816d38af"
local config_home = vim.fn.stdpath('config')
local i = {} -- internal
local M = {} -- public
local B -- backends
local X -- extensions
local P = { -- private
plug_nvim_url = 'https://github.com/spywhere/plug.nvim.git',
old_plug_nvim_path = config_home .. '/lua/plug.lua',
plugs_container = {},
plugs = {},
lazy = {},
hooks = {},
extensions = {},
ext_context = {},
use_api = true,
inject_cmds = false,
lazy_delay = 100,
lazy_interval = 10,
delay_post = 5
}
i.recurse = function (fn)
return (function (next) return next(next) end)(fn)
end
i.generator = function (fn, default)
return i.recurse(function (next)
return function (value)
return fn(next(next), value)
end
end)(default)
end
i.soft_table = function (fn)
return setmetatable({}, {
__index = function(self, k)
local value = rawget(self, k)
if not value then
return fn(k)
end
return value
end
})
end
P.rawprint = function (format, ...)
vim.cmd('redraw')
vim.notify(string.format(format, ...), vim.log.levels.INFO)
end
P.print = function (format, ...)
return P.rawprint(string.format('plug.nvim: %s', format), ...)
end
P.for_each = function (fn, mutable)
local plugs = vim.tbl_extend('force', {}, P.plugs)
if mutable then
P.plugs = {}
end
for _, plugin in ipairs(plugs) do
fn(plugin)
end
end
P.auto = function (event, func)
vim.api.nvim_create_autocmd(event, {
group = vim.api.nvim_create_augroup('__plug_nvim__', {}),
callback = func
})
end
P.inject_command = function (cmd, expr)
local expression = {
'cnoreabbrev',
cmd,
'<c-r>=(getcmdtype()==\':\'',
'&&',
'getcmdpos()==1',
'?',
string.format('\'%s \\| %s\'', expr, cmd),
':',
string.format('\'%s\'', cmd),
')<cr>'
}
vim.api.nvim_exec(table.concat(expression, ' '), false)
end
P.has_hook = function (event)
return P.hooks[event] and next(P.hooks[event])
end
P.raw_dispatch = function (event, keep_false, value, ...)
if not P.hooks[event] then
return value
end
local new_value = value
for _, handler in ipairs(P.hooks[event]) do
local result = handler(P.ext_context, new_value, ...)
if result == false then
if keep_false then
return false
else
return new_value
end
elseif result ~= nil then
new_value = result
end
end
return new_value
end
P.dispatch = function (event, ...)
return P.raw_dispatch(event, false, ...)
end
P.ext_dispatch = function (name)
return function (event, ...)
return P.dispatch(name .. '.' .. event, ...)
end
end
P.hook = function (event, handler)
if not P.hooks[event] then
P.hooks[event] = {}
end
table.insert(P.hooks[event], handler)
end
P.load = function (plugin)
local options = plugin.options or {}
if P.backend.lazy and P.backend.lazy.key then
options[P.backend.lazy.key] = plugin.lazy
end
if plugin.lazy and P.backend.lazy then
if P.backend.lazy.setup then
P.backend.lazy.setup(plugin, options)
end
options.lazy = nil
table.insert(P.lazy, plugin)
else
table.insert(P.plugs, plugin)
end
local perform_post = function ()
vim.defer_fn(function () P.post(plugin, false) end, P.delay_post)
end
options = P.dispatch('plugin_options', options, perform_post, plugin)
P.backend.setup(plugin.name, options)
end
P.post = function (plugin, is_lazy)
local perform_post = function ()
vim.defer_fn(function () P.post(plugin, is_lazy) end, P.delay_post)
end
P.dispatch('plugin_post', plugin, is_lazy, perform_post)
end
P.schedule_lazy = function ()
local delay = 0
if P.backend.lazy then
for _, plugin in ipairs(P.lazy) do
vim.defer_fn(function ()
if P.backend.lazy.load then
P.backend.lazy.load(plugin.identifier)
end
vim.defer_fn(function ()
P.post(plugin, true)
end, P.delay_post)
end, delay)
delay = delay + P.lazy_interval
end
end
P.lazy = {}
end
P.functions = {
PlugUpgrade = function ()
local plug_nvim_path = vim.fn.fnamemodify(
debug.getinfo(1, 'S').source:sub(2), ':p'
)
if vim.fn.filereadable(vim.fn.expand(plug_nvim_path)) == 0 then
-- plug.nvim is loaded but not found, assumming it's on development
-- environment
P.rawprint(
'plug.nvim cannot be found on default location, skipping upgrade'
)
return
end
if vim.fn.filereadable(vim.fn.expand(P.old_plug_nvim_path)) ~= 0 then
-- plug.nvim is found on old location, mark it as old
P.rawprint(
'plug.nvim has adopt packages (see \':h packages\'), ' ..
'updating the previous installation as old'
)
vim.fn.rename(P.old_plug_nvim_path, P.old_plug_nvim_path .. '.old')
end
P.rawprint('Downloading the latest version of plug.nvim')
local tmp = vim.fn.tempname()
local new_file = tmp .. '/plug.lua'
local clone_cmd = {
'git', 'clone', '--depth', '1'
}
if P.plug_nvim_branch then
table.insert(clone_cmd, '--branch')
table.insert(clone_cmd, P.plug_nvim_branch)
end
table.insert(clone_cmd, P.plug_nvim_url)
table.insert(clone_cmd, tmp)
clone_cmd[true] = vim.types.array
local output = vim.fn.system(clone_cmd)
if vim.v.shell_error ~= 0 then
P.rawprint('Error upgrading plug.nvim: %s', output)
return
end
local sha256 = function (path)
return vim.fn.sha256(table.concat(vim.fn.readfile(path), '\n'))
end
if sha256(plug_nvim_path) == sha256(new_file) then
P.rawprint('plug.nvim is already up-to-date')
else
vim.fn.rename(plug_nvim_path, plug_nvim_path .. '.old')
vim.fn.rename(new_file, plug_nvim_path)
P.rawprint('plug.nvim has been upgraded')
end
end
}
P.setup_functions = function ()
for name, fn in pairs(P.functions) do
_G[name] = fn
end
end
P.setup_injections = function ()
if P.inject_cmds then
for name, _ in pairs(P.functions) do
P.inject_command(name, string.format('lua %s()', name))
end
end
end
P.to_plugin = function (plugin, options)
local name = plugin
local definition = {}
if type(name) == 'string' then
definition.options = options
else
definition = {}
for k, v in pairs(name) do
if type(k) == 'string' then
definition[k] = v
else
name = v
end
end
if type(name) ~= 'string' then
name = definition.name or definition.url or definition.dir
end
end
definition.name = name
definition.identifier = vim.fn.fnamemodify(name, ':t:s?\\.git$??')
return definition
end
P.plugin_mutator = function (plugin)
P.plugs_container[plugin.name] = {
plugin = plugin
}
plugin = P.raw_dispatch('plugin', true, plugin, P.hold_plugin)
if plugin == false then
return
end
return plugin
end
P.add_plugin = function (plugin, mutator)
local containment = P.plugs_container[plugin.name]
local new_plugin = plugin
if mutator then
new_plugin = mutator(plugin)
end
if containment and containment.mutator then
new_plugin = containment.mutator(
plugin, {
plugin = containment.plugin,
hold = containment.index and true or false
}
)
if not new_plugin then
return
end
if containment.index then
P.plugs[containment.index] = new_plugin
else
table.insert(P.plugs, new_plugin)
end
elseif new_plugin and not containment then
table.insert(P.plugs, new_plugin)
else
return
end
P.plugs_container[plugin.name] = {
plugin = new_plugin
}
end
P.hold_plugin = function (mutator, ...)
local plugin
if type(mutator) == 'function' then
plugin = P.to_plugin(...)
else
plugin = P.to_plugin(mutator, ...)
mutator = function (v) return v end
end
local containment = P.plugs_container[plugin.name]
if containment then
P.plugs_container[plugin.name].mutator = mutator
end
P.add_plugin(plugin)
if not containment then
P.plugs_container[plugin.name] = {
plugin = plugin,
index = #(P.plugs),
mutator = mutator
}
end
end
P.proxy_key = function (plugin, options, from, to)
if not plugin[from] then
return
end
local value = plugin[from]
local to_key = to or from
if type(to_key) == 'function' then
to_key = to_key(value)
end
if to_key == nil then
return
end
options[to_key] = value
end
P.proxy_to_options = function (from, to)
return function (_, options, _, plugin)
return P.proxy_key(plugin, options, from, to)
end
end
M.begin = function (options)
local opts = options or {}
vim.validate {
backend = { opts.backend, { 's', 't' }, true },
lazy_delay = { opts.lazy_delay, 'n', true },
lazy_interval = { opts.lazy_interval, 'n', true },
delay_post = { opts.delay_post, 'n', true },
extensions = { opts.extensions, 't', true },
update_branch = { opts.update_branch, 's', true }
}
if type(opts.backend) == 'table' then
P.backend = opts.backend
elseif not opts.backend then
local backends = vim.tbl_keys(B)
table.sort(backends)
P.print(
'Backend is required. Supported backends: %s',
table.concat(backends, ', ')
)
return
else
-- deprecated
local backendfn = B[opts.backend]
if not backendfn then
P.print('Unsupported backend: %s', opts.backend)
return
end
local is_ok, backend = pcall(backendfn, opts.options)
if not is_ok then
P.print(
'Unable to use a backend \'%s\':\n%s',
opts.backend, vim.inspect(error)
)
return
else
P.backend = backend
P.print(
'[Deprecated] Backend setting through string is now deprecated'
)
end
end
if
type(P.backend) ~= 'table' or
type(P.backend.name) ~= 'string' or
type(P.backend.setup) ~= 'function'
then
P.backend = nil
if type(opts.backend) == 'table' then
P.print(
'Backend %s is not a valid backend',
opts.backend.name and string.format(
'\'%s\'', opts.backend.name
) or 'given'
)
else
P.print('Backend \'%s\' is not a valid backend', opts.backend)
end
return
end
if opts.lazy_delay then
P.lazy_delay = opts.lazy_delay
end
if opts.lazy_interval then
P.lazy_interval = opts.lazy_interval
end
if opts.delay_post then
P.delay_post = opts.delay_post
end
if opts.extensions then
local context = P.backend.context or {}
context.backend = P.backend.name
for _, extension in ipairs(opts.extensions) do
if type(extension) == 'function' then
extension(P.hook, context)
elseif type(extension) == 'table' and extension.name then
local name = extension.name
if not P.extensions[name] then
P.extensions[name] = true
extension.entry(P.hook, P.ext_dispatch(name), context)
end
end
end
end
if not next(P.plugs) then
P.use_api = false
end
if opts.update_branch then
P.plug_nvim_branch = opts.update_branch
end
end
M.install = function (...)
local definition = P.to_plugin(...)
-- if plugin is this plugin, then inject upgrade function
if definition.name == 'spywhere/plug.nvim' then
P.inject_cmds = true
P.print(
'[Deprecated] Upgrade command injection is no longer support'
)
return
end
P.add_plugin(definition, not P.use_api and P.plugin_mutator or nil)
end
M.ended = function ()
if not P.backend then
return
elseif vim.fn.has('nvim') == 0 then
P.rawprint('plug.nvim only supported in neovim')
return
elseif vim.fn.has('nvim-0.7.0') == 0 then
P.rawprint('plug.nvim requires neovim v0.7.0 or later')
return
end
P.setup_functions()
if P.use_api then
P.plugs_container = {}
P.for_each(function (p) P.add_plugin(p, P.plugin_mutator) end, true)
end
P.plugs_container = {}
P.plugs = P.dispatch('plugin_collected', P.plugs)
-- process pre-setup
-- perform before plugin manager installation to allow custom function to
-- dictate how plugin manager should behave
P.dispatch('pre_setup', P.plugs)
if P.raw_dispatch('setup', true, P.plugs) == false then
return
end
if P.backend.pre_setup then
P.backend.pre_setup()
end
P.for_each(P.load, true)
if P.backend.post_setup then
P.backend.post_setup()
end
if P.raw_dispatch('post_setup', true, P.plugs) == false then
return
end
P.for_each(P.post)
if next(P.lazy) then
vim.defer_fn(P.schedule_lazy, P.lazy_delay)
end
P.setup_injections()
P.dispatch('done')
P.plugs = {}
end
M.setup = function (opts, fn)
local is_fn = type(opts) == 'function'
if not is_fn and next(P.plugs) then
M.begin(opts)
return M.ended()
end
if is_fn or type(fn) == 'function' then
M.begin(not is_fn and opts or nil)
if is_fn then
opts(M.install)
else
fn(M.install)
end
return M.ended()
end
M.begin(opts)
return i.generator(function (next)
return function (plugin)
if plugin == nil or plugin == '' or #plugin == 0 then
return M.ended()
end
M.install(plugin)
return next()
end
end)
end
B = i.soft_table(function (k) -- backends
return function ()
return {
name = k
}
end
end)
B.lazy = function (ctx)
local M = {
name = 'lazy.nvim',
plugins = {},
lazy_path = vim.fn.stdpath('data') .. '/lazy/lazy.nvim',
lazy_url = 'https://github.com/folke/lazy.nvim.git'
}
M.is_installed = function ()
return not not vim.loop.fs_stat(M.lazy_path)
end
M.install = function ()
-- git is not found
if vim.fn.executable('git') == 0 then
return false
end
vim.cmd(
'silent !git clone --filter=blob:none ' .. M.lazy_url .. ' --branch=stable ' .. M.lazy_path
)
return true
end
M.lazy = {
key = 'lazy'
}
M.pre_setup = function ()
vim.opt.rtp:prepend(M.lazy_path)
end
M.setup = function (name, options)
options[1] = name
table.insert(M.plugins, options)
end
M.post_setup = function ()
require('lazy').setup(M.plugins, ctx)
end
return M
end
B['lazy.nvim'] = B.lazy
B.packer = function (ctx)
local handlers = {}
local M = {
name = 'packer.nvim',
packer_path = vim.fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim',
packer_url = 'https://github.com/wbthomason/packer.nvim',
context = {
install_command = function ()
require('packer').sync()
end,
setup_handler = function (ext, name, kind)
local keyname = ext .. '.' .. name .. '.' .. (kind or 'config')
if handlers[keyname] then
return
end
require('packer').set_handler(name, function (_, plugin, value)
local call = string.format(
'require(\'plug\').extension.%s[\'%s\'](\'%s\')',
ext, value, name
)
if not kind or kind == 'config' then
if type(plugin.config) == 'table' then
table.insert(plugin.config, call)
else
plugin.config = { call }
end
else
plugin[kind] = call
end
end)
handlers[keyname] = true
end
}
}
M.is_installed = function ()
return vim.fn.empty(vim.fn.glob(M.packer_path)) == 0
end
M.install = function ()
-- git is not found
if vim.fn.executable('git') == 0 then
return false
end
vim.cmd(
'silent !git clone --depth 1 ' .. M.packer_url .. ' ' .. M.packer_path
)
return true
end
M.lazy = {
key = 'opt'
}
M.pre_setup = function ()
vim.cmd('packadd packer.nvim')
local packer = require('packer')
packer.init(ctx)
packer.reset()
M.setup('wbthomason/packer.nvim', {
opt = true
})
return packer
end
M.setup = function (name, options)
options[1] = name
require('packer').use(options)
end
return M
end
B['packer.nvim'] = B.packer
B.pckr = function (ctx)
local loaders = {}
local M = {
name = 'pckr.nvim',
pckr_path = vim.fn.stdpath('data') .. '/pckr/pckr.nvim',
pckr_url = 'https://github.com/lewis6991/pckr.nvim',
context = {
install_command = function ()
require('pckr').sync()
end
}
}
M.is_installed = function ()
return not not vim.loop.fs_stat(M.pckr_path)
end
M.install = function ()
-- git is not found
if vim.fn.executable('git') == 0 then
return false
end
vim.cmd(string.format(
'silent !git clone --filter=blob:none %s %s'
, M.pckr_url, M.pckr_path
))
return true
end
M.lazy = {
setup = function (plugin, options)
if options.cond then
-- already have a custom loader, skip lazy loading
return
end
options.cond = function (load_plugin)
if not loaders[plugin.identifier] then
loaders[plugin.identifier] = load_plugin
end
end
end,
load = function (plugin)
if loaders[plugin] then
loaders[plugin]()
end
end
}
M.pre_setup = function ()
vim.opt.rtp:prepend(M.pckr_path)
return require('pckr').setup(ctx)
end
M.setup = function (name, options)
options[1] = name
require('pckr').add(options)
end
return M
end
B['pckr.nvim'] = B.pckr
B.vim_plug = function (ctx)
local config = vim.fn.stdpath('data')
local M = {
name = 'vim-plug',
plug_url = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim',
plug_path = config .. '/site/autoload/plug.vim',
context = {
install_command = 'PlugInstall --sync | q'
}
}
local plug = function (name)
return function (...)
return vim.fn['plug#'..name](...)
end
end
M.context.has_missing_plugins = function ()
local is_plugin_missing = function (plugin)
return vim.fn.isdirectory(plugin.dir) == 0
end
local plugins = vim.tbl_values(vim.g.plugs)
local missing_plugins = vim.tbl_filter(is_plugin_missing, plugins)
return next(missing_plugins)
end
M.is_installed = function ()
return vim.fn.filereadable(vim.fn.expand(M.plug_path)) ~= 0
end
M.install = function ()
-- curl is not found
if vim.fn.executable('curl') == 0 then
return false
end
vim.cmd(
'silent !curl -fLo ' .. M.plug_path .. ' --create-dirs ' .. M.plug_url
)
return true
end
M.lazy = {
setup = function (_, options)
options.on = {}
end,
load = plug'load'
}
M.pre_setup = function ()
if ctx then
return plug'begin'(ctx)
else
return plug'begin'()
end
end
M.setup = function (name, options)
options[true] = vim.types.dictionary
plug''(name, options)
end
M.post_setup = plug'end'
return M
end
B['vim-plug'] = B.vim_plug
X = i.soft_table(function (k) -- extensions
P.print('Extension \'%s\' is not available', k)
return function ()
end
end)
P.run_install_plugins = function(install_context, first_install)
local command = install_context.install_command
if not command then
return function () end
end
if type(command) == 'string' then
return function ()
vim.cmd(command)
end
else
return function ()
return command(first_install)
end
end
end
P.install_missing_plugins = function (install_context)
return function ()
if not install_context.has_missing_plugins() then
return
end
local fn = P.run_install_plugins(install_context, false)
if fn then
fn()
end
end
end
P.execute_shell = function (command, callback)
local luv = vim.loop
local handle
local timer
local output = {}
local stdout = luv.new_pipe()
local stderr = luv.new_pipe()
local options = command.options or {}
options.stdio = { nil, stdout, stderr }
local cmd = table.remove(command.cmd, 1)
options.args = command.cmd
handle = luv.spawn(
cmd,
options,
function(code, signal)
output.code = code
output.signal = signal
handle:close()
if timer then
timer:stop()
timer:close()
end
local check = luv.new_check()
luv.check_start(check, function ()
for _, pipe in pairs(options.stdio) do
if not luv.is_closing(pipe) then
return
end
end
luv.check_stop(check)
vim.defer_fn(function ()
callback(output)
end, 0)
end)
end
)
local function pipe_output(pipe, target, err_target)
luv.read_start(pipe, function (err, data)
if err and err_target then
output[err_target] = string.format(
'%s%s',
output[err_target] or '',
data
)
end
if data == nil then
luv.read_stop(pipe)
luv.close(pipe)
else
output[target] = string.format('%s%s', output[target] or '', data)
end
end)
end
pipe_output(stdout, 'stdout')
pipe_output(stderr, 'stderr')
if command.timeout then
timer = luv.new_timer()
timer:start(command.timeout * 1000, 0, function ()
timer:stop()
timer:close()
if not luv.is_active(handle) then
return
end
output.signal = 'sigint'
luv.process_kill(handle, output.signal)
handle:close()
for _, pipe in pairs(options.stdio) do
luv.close(pipe)
end
output.code = -9999
callback(output)
end)
end
end
-- extension for auto-install plugin manager and missing plugins
X.auto_install = function (options)
local opts = options or {}
vim.validate {
plug = { opts.plug, 'b', true },
manager = { opts.manager, 'b', true },
missing = { opts.missing, 'b', true },
post_install_delay = { opts.post_install_delay, 'n', true }
}
opts = vim.tbl_extend('keep', opts, {
plug = true,
manager = true,
missing = true,
post_install_delay = 100
})
local function installation(install_context)
return function (ctx)