repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: puc

a77799dd638bc8268479898168465cf9390a2221

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+160 / −0 text lines

Diff layout

neovim/puck.lua

Added
new file mode 100644

+160 / −0 text lines

1-- Install tarballs into data dir
2-- Put local plugins on runtimepath
3-- Generate helptags ALL
4-- project local plugin settings ?
5-- make this module async --> emit PuckDone event?
6-- Install treesitter parser into data dir
7-- Build parsers and put them where?
8-- Cache lua byte code ?
9
10--FIXME: temp
11vim.opt.background = 'light'
12vim.cmd.colorscheme 'nugu'
14-- TODO export some kind of structure
15local dev = 'plugin_under_development'
16local gh = 'plugin_from_github'
17local gh_format = 'https://github.com/%s/archive/%s.tar.gz'
19local as_name = function(plugin_coords)
20 return (plugin_coords):gsub('(%w+)%.?%w*', '%1')
21end
23local download_plugin_into = function(plugin_tarball_url, plugin_install_path)
24 --TODO
26end
28local delete_directory_recursive = function(path)
29 local stat = vim.uv.fs_stat(path)
30 if stat and stat.type == "directory" then
31 local dir = vim.uv.fs_scandir(path)
32 if dir then
33 while true do
34 local name, type = vim.uv.fs_scandir_next(dir)
35 if not name then
36 break
37 end
39 local full_path = vim.fs.joinpath(path, name)
40 if type == "directory" then
41 return delete_directory_recursive(full_path)
42 else
43 return vim.uv.fs_unlink(full_path)
44 end
45 end
46 end
47 return vim.uv.fs_rmdir(path)
48 else
49 return false
50 end
52 return true
53end
55local install_plugin = function(puck_root, plugin_type, plugin_coords, plugin_rev)
56 local plugin_name = as_name(plugin_coords)
57 local plugin_install_path = vim.fs.normalize(vim.fs.joinpath(puck_root, plugin_name))
58 local plugin_install_path_stat = vim.uv.fs_stat(plugin_install_path)
59 local plugin_already_exists = plugin_install_path_stat and plugin_install_path_stat.type == 'directory'
61 local plugin_install_rev_path = vim.fs.normalize(puck_root, plugin_name .. '.rev')
63 -- either do nothing or update/fresh install
64 if(vim.uv.fs_access(plugin_install_rev_path,'R') then
65 local current_rev = io:open(plugin_install_rev_path, 'r'):read()
66 if current_rev == plugin_rev then return end
67 end
68 -- rev is different, must be update (we don`t care if up or down) or fresh install
69 local removed = delete_directory_recursive(plugin_install_path)
70 local plugin_tarball_url = gh_format:format(plugin_coords, plugin_rev)
71 local ok = xpcall(download_plugin_into,plugin_tarball_url, plugin_install_path)
72 if ok then
73 io.open(plugin_install_rev_path, 'w+'):write(plugin_rev)
74 if removed then
75 vim.notify('Plugin ' .. plugin_coords .. '@' .. plugin_rev .. ' updated!', vim.log.levels.INFO)
76 else
77 vim.notify('Plugin ' .. plugin_coords .. '@' .. plugin_rev .. ' installed!', vim.log.levels.INFO)
78 end
80 else
81 vim.notify('Failed to download tarball for plugin ' .. plugin_coords .. '@' .. plugin_rev ..'!', vim.log.levels.ERROR)
82 end
84end
86local delete_unused_plugins = function(puck_root) end
88local register_local_plugin = function(plugin_coords)
89 local plugin_path = vim.fs.normalize(plugin_coords)
90 local plugin_path_stat = vim.uv.fs_stat(plugin_path)
92 if( plugin_path_stat and plugin_path_stat.type == 'directory') then
93 vim.opt.runtimepath:prepend(plugin_path)
94 else
95 vim.notify('Failed to load local plugin ' .. plugin_path .. '!',vim.log.levels.ERROR)
96 end
97end
99local load_local_plugin = function(plugin_coords)
100 local plugin_name = as_name(plugin_coords)
101 local plugin_init = {}
102 vim.tbl_extend('keep',plugin_init, vim.api.nvim_get_runtime_file('plugin/' .. plugin_name .. '.vim', false ))
103 vim.tbl_extend('keep',plugin_init, vim.api.nvim_get_runtime_file('plugin/' .. plugin_name .. '.lua', false ))
104 for _, init in pairs(plugin_init) do
105 vim.cmd.source(init)
106 end
107end
109local load_registered_plugin = function(plugin_name)
110 -- TODO
111end
113local setup = function(options)
114 options = options or {}
115 options.plugins = options.plugins or {}
116 -- take control of loading plugins.
117 -- that means we have to take care of builtin plugins later
118 vim.opt.loadplugins = false
120 local puck_root = vim.fs.normalize(vim.fn.stdpath 'data' .. '/site/pack/puck')
121 vim.fn.mkdir(puck_root, 'p')
123 for _, plugin in pairs(plugins) do
124 local plugin_type = plugin[1]
125 local plugin_coords = plugin[2]
126 local plugin_rev = plugin[3]
127 if plugin_type == dev then
128 register_local_plugin(plugin_coords)
129 else
130 install_plugin(puck_root, plugin_type, plugin_coords, plugin_rev)
131 end
132 end
134 delete_unused_plugins(puck_root)
136 -- manually load builtin plugins, that we disabled earlier
137 -- loads only a subset of builtins, that i find useful.
138 load_local_plugin 'plugin/shada.vim'
139 load_local_plugin 'plugin/tutor.vim'
140 load_local_plugin 'plugin/spellfile.vim'
141 load_local_plugin 'plugin/osc52.lua'
142 -- can this be useful on win32?
143 -- load_local_plugin 'plugin/man.lua'
144 load_local_plugin 'plugin/editorconfig.lua'
145end
147-- TODO move this outside
148-- testing the puck
149local plugins = {
150 { dev , '~\\Workspaces\\venn.nvim' },
151 { gh, 'nyoom-engineering/oxocarbon.nvim', 'c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2' },
152}
153setup { plugins = plugins }
154load_registered_plugin'oxocarbon'
155vim.cmd.colorscheme'oxocarbon'
157return {
158 load = load_registered_plugin,
159 setup = setup,
160}