24 24 local as_name = function ( plugin_coords )
25 - return vim.fs.basename(plugin_coords):gsub(
'(%w+)%.?%w*',
'%1' )
25 + return vim.fs.basename( plugin_coords ):gsub(
'(%w+)%.?%w*',
'%1' )
28 -local configure_plugin = function( plugin_name )
29 - local config
= 'config.' .. plugin_name
30 - vim.schedule(
function()
31 - local ok
= pcall(
require, config)
33 - vim.notify(
string.
format(
'unable to load configuration for %s at %s', plugin_name, config), vim.log.levels.WARN)
28 +local configure_plugin = function ( plugin_name )
29 + local config
= 'config.' .. plugin_name
30 + vim.schedule(
function ()
31 + local ok
= pcall(
require, config )
33 + vim.notify(
string.
format(
'unable to load configuration for %s at %s', plugin_name, config ), vim.log.levels.WARN )
38 -local download_plugin_into = function ( puck_root, plugin_name, plugin_tarball_url, plugin_install_path)
40 - puck_root = { puck_root,
'string' },
41 - plugin_name = { plugin_name,
'string'},
42 - plugin_tarball_url = { plugin_tarball_url,
'string' },
43 - plugin_install_path = { plugin_install_path,
'string'},
38 +local download_plugin_into = function ( puck_root, plugin_name, plugin_tarball_url, plugin_install_path )
40 + puck_root = { puck_root,
'string', },
41 + plugin_name = { plugin_name,
'string', },
42 + plugin_tarball_url = { plugin_tarball_url,
'string', },
43 + plugin_install_path = { plugin_install_path,
'string', },
46 - assert(vim.fn.executable
'curl',
'curl not found')
47 - assert(vim.fn.executable
'tar',
'tar not found')
46 + assert( vim.fn.executable
'curl',
'curl not found' )
47 + assert( vim.fn.executable
'tar',
'tar not found' )
52 - local tarball_data_stream
= vim.uv.new_pipe(
true)
52 + local tarball_data_stream
= vim.uv.new_pipe(
true )
54 - local curl_handle, curl_pid
= vim.uv.spawn(
'curl',
56 - args = {
'--silent',
'--location', plugin_tarball_url },
58 - stdio = {
nil, tarball_data_stream,
nil},
61 - function(code, signal)
63 - error(
'curl', code, signal)
66 - local tar_handle, tar_pid
= vim.uv.spawn(
'tar',
68 - args = {
'--extract',
'--gzip',
'--file',
'-' },
70 - stdio = { tarball_data_stream,
nil,
nil},
73 - function(code, signal)
75 - error(
'tar done', code, signal)
54 + local curl_handle, curl_pid
= vim.uv.spawn(
'curl',
56 + args = {
'--silent',
'--location', plugin_tarball_url, },
58 + stdio = {
nil, tarball_data_stream,
nil, },
61 + function ( code, signal )
63 + error(
'curl', code, signal )
66 + local tar_handle, tar_pid
= vim.uv.spawn(
'tar',
68 + args = {
'--extract',
'--gzip',
'--file',
'-', },
70 + stdio = { tarball_data_stream,
nil,
nil, },
73 + function ( code, signal )
75 + error(
'tar done', code, signal )
78 - local contains_name = function(name, path)
return name:find(plugin_name,
0,
true)
end 79 - local extracted_dir
= vim.fs.find( contains_name, {
path = puck_root,
type =
'directory',
limit =
1 })
80 - assert(
#extracted_dir
~= 0,
'No directory was found in tarball')
81 - assert(
#extracted_dir
== 1,
'Too many directories were found in tarball. Expected one!')
83 - local ok
= vim.uv.fs_rename(extracted_dir[
1], plugin_install_path)
84 - assert(ok,
string.
format(
'Failed to move extracted plugin from %s to %s.', extracted_dir[
1], plugin_install_path))
85 - configure_plugin(plugin_name)
78 + local contains_name = function ( name, path )
79 + return name:find( plugin_name,
82 + local extracted_dir
= vim.fs.find( contains_name,
83 + {
path = puck_root,
type =
'directory',
limit =
1, } )
84 + assert(
#extracted_dir
~= 0,
'No directory was found in tarball' )
85 + assert(
#extracted_dir
== 1,
86 + 'Too many directories were found in tarball. Expected one!' )
88 + local ok
= vim.uv.fs_rename( extracted_dir[
1], plugin_install_path )
90 + string.
format(
'Failed to move extracted plugin from %s to %s.',
91 + extracted_dir[
1], plugin_install_path ) )
92 + configure_plugin( plugin_name )
88 - vim.uv.shutdown(tarball_data_stream,
function()
89 - vim.uv.close(curl_handle)
90 - vim.uv.close(tar_handle)
95 + vim.uv.shutdown( tarball_data_stream,
function ()
96 + vim.uv.close( curl_handle )
97 + vim.uv.close( tar_handle )
94 101 local delete_directory_recursive = function ( path )
121 -local as_url_format = function(plugin_type)
122 - assert(plugin_type
~= dev,
'local plugins need not have an url format!')
123 - if plugin_type
== gh
then return gh_format
end 124 - if plugin_type
== cb
then return cb_format
end 125 - if plugin_type
== srht
then return srht_format
end 126 +local as_url_format = function ( plugin_type )
127 + assert( plugin_type
~= dev,
'local plugins need not have an url format!' )
128 + if plugin_type
== gh
then return gh_format
end 129 + if plugin_type
== cb
then return cb_format
end 130 + if plugin_type
== srht
then return srht_format
end 127 - error(
'unknown plugin type '..plugin_type
..' given.')
132 + error(
'unknown plugin type ' .. plugin_type
.. ' given.' )
130 -local install_plugin = function ( puck_root, plugin_type, plugin_coords, plugin_rev)
135 +local install_plugin = function ( puck_root, plugin_type, plugin_coords, plugin_rev )
131 136 local plugin_name
= as_name( plugin_coords )
132 137 local plugin_install_path
= vim.fs.normalize( vim.fs.joinpath( puck_root, plugin_name ) )
133 138 local plugin_install_path_stat
= vim.uv.fs_stat( plugin_install_path )
134 139 local plugin_already_exists
= plugin_install_path_stat
and plugin_install_path_stat.type
== 'directory' 136 - local plugin_install_rev_path
= vim.fs.normalize( vim.fs.joinpath(puck_root, plugin_name
.. '.rev' ))
141 + local plugin_install_rev_path
= vim.fs.normalize( vim.fs.joinpath( puck_root, plugin_name
.. '.rev' ) )
139 144 if (vim.uv.fs_access( plugin_install_rev_path,
'R' ))
then 140 145 local plugin_install_rev_file
= io.
open( plugin_install_rev_path,
'r' )
141 - if not plugin_install_rev_file
then vim.notify(
'Unable to read rev file ' .. plugin_install_rev_path, vim.log.levels.ERROR)
end 146 + if not plugin_install_rev_file
then 147 + vim.notify(
'Unable to read rev file ' .. plugin_install_rev_path,
148 + vim.log.levels.ERROR )
142 150 local current_rev
= plugin_install_rev_file:read()
143 151 plugin_install_rev_file:close()
144 152 if current_rev
== plugin_rev
then 145 - configure_plugin(plugin_name)
153 + configure_plugin( plugin_name )
150 158 local removed
= delete_directory_recursive( plugin_install_path )
151 - local url_format
= as_url_format(plugin_type)
159 + local url_format
= as_url_format( plugin_type )
152 160 local plugin_tarball_url
= url_format:format( plugin_coords, plugin_rev )
153 - download_plugin_into(puck_root, plugin_name, plugin_tarball_url, plugin_install_path, callback )
154 - local mode
= vim.uv.fs_access(plugin_install_rev_path,
'W')
and 'w+' or 'w' 155 - local plugin_install_rev_file
= io.
open( plugin_install_rev_path, mode)
156 - if not plugin_install_rev_file
then vim.notify(
'Unable to write rev file ' .. plugin_install_rev_path, vim.log.levels.ERROR)
end 161 + download_plugin_into( puck_root, plugin_name, plugin_tarball_url, plugin_install_path, callback )
162 + local mode
= vim.uv.fs_access( plugin_install_rev_path,
'W' )
and 'w+' or 'w' 163 + local plugin_install_rev_file
= io.
open( plugin_install_rev_path, mode )
164 + if not plugin_install_rev_file
then 165 + vim.notify(
'Unable to write rev file ' .. plugin_install_rev_path,
166 + vim.log.levels.ERROR )
157 168 plugin_install_rev_file:write( plugin_rev )
158 169 plugin_install_rev_file:close()
160 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' updated!', vim.log.levels.INFO )
171 + vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' updated!', vim.log.levels.INFO )
162 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' installed!', vim.log.levels.INFO )
173 + vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' installed!', vim.log.levels.INFO )
166 177 local delete_unused_plugins = function ( puck_root )
end 168 179 local register_local_plugin = function ( workspace, plugin_coords )
169 - local plugin_path
= vim.fs.normalize( vim.fs.joinpath(workspace, vim.fs.basename(plugin_coords) ) )
180 + local plugin_path
= vim.fs.normalize( vim.fs.joinpath( workspace, vim.fs.basename( plugin_coords ) ) )
170 181 local plugin_path_stat
= vim.uv.fs_stat( plugin_path )
172 183 if (plugin_path_stat
and plugin_path_stat.type
== 'directory')
then 189 200 local load_registered_plugin = function ( plugin_name )
190 - vim.cmd.packadd(plugin_name)
201 + vim.cmd.packadd( plugin_name )
192 - return require(plugin_name)
203 + return require( plugin_name )
195 206 local setup = function ( options )
196 207 options
= options
or {}
198 - [
'options.workspace'] = { options.workspace,
'string'},
209 + [
'options.workspace'] = { options.workspace,
'string', },
201 212 options.plugins
= options.plugins
or {}
212 223 local plugin_coords
= plugin[
2]
213 224 local plugin_rev
= plugin[
3]
214 225 if plugin_type
== dev
then 215 - register_local_plugin(options.workspace, plugin_coords )
226 + register_local_plugin( options.workspace, plugin_coords )
219 - install_plugin( puck_root, plugin_type, plugin_coords, plugin_rev)
230 + install_plugin( puck_root, plugin_type, plugin_coords, plugin_rev )
238 249 load = load_registered_plugin,
241 - github = {
type = gh,
format = gh_format },
242 - codeberg = {
type = cb,
format = cb_format },
243 - sourcehut = {
type = srht,
format = srht_format },
244 - development = {
type = dev,
format =
nil },
252 + github = {
type = gh,
format = gh_format, },
253 + codeberg = {
type = cb,
format = cb_format, },
254 + sourcehut = {
type = srht,
format = srht_format, },
255 + development = {
type = dev,
format =
nil, },