15 15 local dev
= 'plugin_under_development' 16 16 local gh
= 'plugin_from_github' 17 +local srht
= 'plugin_from_srht' 18 +local cb
= 'plugin_from_codeberg' 17 19 local gh_format
= 'https://github.com/%s/archive/%s.tar.gz' 20 +local cb_format
= 'https://codeberg.org/%s/archive/%s.tar.gz' 21 +local srht_format
= 'https://git.sr.ht/%s/archive/%s.tar.gz' 19 -local as_name = function(plugin_coords)
20 - return (plugin_coords):gsub(
'(%w+)%.?%w*',
'%1')
25 +local as_name = function ( plugin_coords )
26 + return vim.fs.basename(plugin_coords):gsub(
'(%w+)%.?%w*',
'%1' )
23 -local download_plugin_into = function(plugin_tarball_url, plugin_install_path)
29 +local download_plugin_into = function ( plugin_tarball_url, plugin_install_path )
31 + assert(vim.fn.executable
'curl',
'curl not found')
32 + assert(vim.fn.executable
'tar',
'tar not found')
34 + vim.fn.mkdir( plugin_install_path,
'p' )
36 + local tarball_data_stream
= vim.uv.new_pipe(
true)
37 + local error_stream
= vim.uv.new_pipe()
39 + vim.uv.read_start(error_stream,
function(err, data)
40 + assert(
not err, err)
41 + if data
then vim.notify(data, vim.log.levels.ERROR)
end 44 + local curl_handle, curl_pid
= vim.uv.spawn(
'curl',
46 + args = {
'--silent',
'--location', plugin_tarball_url },
47 + cwd = plugin_install_path,
48 + stdio = {
nil, tarball_data_stream, error_stream},
51 + function(code, signal)
52 + vim.print(
'curl done', code, signal)
54 + local tar_handle, tar_pid
= vim.uv.spawn(
'tar',
56 + args = {
'--extract',
'--gzip',
'--file',
'-' },
57 + cwd = plugin_install_path,
58 + stdio = { tarball_data_stream,
nil, error_stream},
61 + function(code, signal)
62 + vim.print(
'tar done', code, signal)
65 + print(curl_handle, curl_handle, tar_handle, tar_pid)
67 + vim.uv.shutdown(tarball_data_stream,
function()
68 + vim.uv.close(curl_handle,
function()
69 + vim.print(
"curl closed")
71 + vim.uv.close(tar_handle,
function()
72 + vim.print(
"tar closed")
28 -local 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)
34 - local name,
type = vim.uv.fs_scandir_next(dir)
39 - local full_path
= vim.fs.joinpath(path, name)
40 - if type == "directory" then 41 - return delete_directory_recursive(full_path)
43 - return vim.uv.fs_unlink(full_path)
77 +local delete_directory_recursive = function ( path )
78 + local stat
= vim.uv.fs_stat( path )
79 + if stat
and stat.type
== 'directory' then 80 + local dir
= vim.uv.fs_scandir( path )
83 + local name,
type = vim.uv.fs_scandir_next( dir )
47 - return vim.uv.fs_rmdir(path)
88 + local full_path
= vim.fs.joinpath( path, name )
89 + if type == 'directory' then 90 + return delete_directory_recursive( full_path )
92 + return vim.uv.fs_unlink( full_path )
96 + return vim.uv.fs_rmdir( path )
55 -local 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')
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 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)
73 - io.
open(plugin_install_rev_path,
'w+'):write(plugin_rev)
75 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' updated!', vim.log.levels.INFO)
77 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' installed!', vim.log.levels.INFO)
81 - vim.notify(
'Failed to download tarball for plugin ' .. plugin_coords
.. '@' .. plugin_rev
..'!', vim.log.levels.ERROR)
104 +local as_url_format = function(plugin_type)
105 + assert(plugin_type
~= dev,
'local plugins need not have an url format!')
106 + if plugin_type
== gh
then return gh_format
end 107 + if plugin_type
== cb
then return cb_format
end 108 + if plugin_type
== srht
then return srht_format
end 110 + error(
'unknown plugin type '..plugin_type
..' given.')
86 -local delete_unused_plugins = function(puck_root)
end 113 +local install_plugin = function ( puck_root, plugin_type, plugin_coords, plugin_rev )
114 + local plugin_name
= as_name( plugin_coords )
115 + local plugin_install_path
= vim.fs.normalize( vim.fs.joinpath( puck_root, plugin_name ) )
116 + local plugin_install_path_stat
= vim.uv.fs_stat( plugin_install_path )
117 + local plugin_already_exists
= plugin_install_path_stat
and plugin_install_path_stat.type
== 'directory' 88 -local 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)
119 + local plugin_install_rev_path
= vim.fs.normalize( vim.fs.joinpath(puck_root, plugin_name
.. '.rev' ))
92 - if( plugin_path_stat
and plugin_path_stat.type
== 'directory')
then 93 - vim.opt.runtimepath:prepend(plugin_path)
95 - vim.notify(
'Failed to load local plugin ' .. plugin_path
.. '!',vim.log.levels.ERROR)
122 + if (vim.uv.fs_access( plugin_install_rev_path,
'R' ))
then 123 + local plugin_install_rev_file
= io.
open( plugin_install_rev_path,
'r' )
124 + if not plugin_install_rev_file
then vim.notify(
'Unable to read rev file ' .. plugin_install_rev_path, vim.log.levels.ERROR)
end 125 + local current_rev
= plugin_install_rev_file:read()
126 + plugin_install_rev_file:close()
127 + if current_rev
== plugin_rev
then return end 130 + local removed
= delete_directory_recursive( plugin_install_path )
131 + local url_format
= as_url_format(plugin_type)
132 + local plugin_tarball_url
= url_format:format( plugin_coords, plugin_rev )
133 + local ok
= pcall( download_plugin_into, plugin_tarball_url, puck_root )
135 + local mode
= vim.uv.fs_access(plugin_install_rev_path,
'W')
and 'w+' or 'w' 136 + local plugin_install_rev_file
= io.
open( plugin_install_rev_path, mode)
137 + if not plugin_install_rev_file
then vim.notify(
'Unable to write rev file ' .. plugin_install_rev_path, vim.log.levels.ERROR)
end 138 + plugin_install_rev_file:write( plugin_rev )
139 + plugin_install_rev_file:close()
141 + vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' updated!', vim.log.levels.INFO )
143 + vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' installed!', vim.log.levels.INFO )
146 + vim.notify(
'Failed to download tarball for plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. '!',
147 + vim.log.levels.ERROR )
99 -local 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)
151 +local delete_unused_plugins = function ( puck_root )
end 153 +local register_local_plugin = function ( workspace, plugin_coords )
154 + local plugin_path
= vim.fs.normalize( vim.fs.joinpath(workspace, vim.fs.basename(plugin_coords) ) )
155 + local plugin_path_stat
= vim.uv.fs_stat( plugin_path )
157 + if (plugin_path_stat
and plugin_path_stat.type
== 'directory')
then 158 + vim.opt.runtimepath:prepend( plugin_path )
160 + vim.notify(
'Failed to load local plugin ' .. plugin_path
.. '!', vim.log.levels.ERROR )
109 -local load_registered_plugin = function(plugin_name)
164 +local load_local_plugin = function ( plugin_coords )
165 + local plugin_name
= as_name( plugin_coords )
166 + local plugin_init
= {}
167 + vim.tbl_extend(
'keep', plugin_init, vim.api.nvim_get_runtime_file(
'plugin/' .. plugin_name
.. '.vim',
false ) )
168 + vim.tbl_extend(
'keep', plugin_init, vim.api.nvim_get_runtime_file(
'plugin/' .. plugin_name
.. '.lua',
false ) )
169 + for _, init
in pairs( plugin_init )
do 170 + vim.cmd.source( init )
113 -local setup = function(options)
114 - options
= options
or {}
115 - options.plugins
= options.plugins
or {}
118 - vim.opt.loadplugins
= false 174 +local load_registered_plugin = function ( plugin_name )
120 - local puck_root
= vim.fs.normalize(vim.fn.stdpath
'data' .. '/site/pack/puck')
121 - vim.fn.mkdir(puck_root,
'p')
178 +local setup = function ( options )
179 + options
= options
or {}
180 + vim.validate { [
'options.workspace'] = { options.workspace,
'string'}}
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)
130 - install_plugin(puck_root, plugin_type, plugin_coords, plugin_rev)
182 + options.plugins
= options.plugins
or {}
183 + plugins
= options.plugins
186 + vim.opt.loadplugins
= false 134 - delete_unused_plugins(puck_root)
188 + local puck_root
= vim.fs.normalize( vim.fn.stdpath
'data' .. '/site/pack/puck' )
189 + vim.fn.mkdir( puck_root,
'p' )
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' 144 - load_local_plugin
'plugin/editorconfig.lua' 191 + for _, plugin
in pairs( plugins )
do 192 + local plugin_type
= plugin[
1]
193 + local plugin_coords
= plugin[
2]
194 + local plugin_rev
= plugin[
3]
195 + if plugin_type
== dev
then 196 + register_local_plugin(options.workspace, plugin_coords )
198 + install_plugin( puck_root, plugin_type, plugin_coords, plugin_rev )
202 + delete_unused_plugins( puck_root )
206 + load_local_plugin
'plugin/shada.vim' 207 + load_local_plugin
'plugin/tutor.vim' 208 + load_local_plugin
'plugin/spellfile.vim' 209 + load_local_plugin
'plugin/osc52.lua' 212 + load_local_plugin
'plugin/editorconfig.lua' 149 217 local plugins
= {
150 - { dev ,
'~\\Workspaces\\venn.nvim' },
151 - { gh,
'nyoom-engineering/oxocarbon.nvim',
'c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2' },
218 + { dev,
'bugabinga/venn.nvim', },
219 + { gh,
'nyoom-engineering/oxocarbon.nvim',
'c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2', },
220 + { srht,
'~adigitoleo/haunt.nvim',
'e3e3c8f45663fed8225ba5efb0af00a2df14a736', },
221 + { cb,
'jthvai/lavender.nvim',
'a5187e6f4afe4b1f2fbcd0fe0bad34c40002ba48', },
222 + { dev,
'bugabinga/auto-dark-mode.nvim',
nil, },
153 -setup {
plugins = plugins }
154 -load_registered_plugin
'oxocarbon' 155 -vim.cmd.colorscheme
'oxocarbon' 224 +setup {
plugins = plugins,
workspace =
'~/Workspace'}
225 +load_registered_plugin
'oxocarbon' 226 +vim.cmd.colorscheme
'oxocarbon' 158 - load = load_registered_plugin,
229 + load = load_registered_plugin,