11 -vim.opt.background
= 'light' 12 -vim.cmd.colorscheme
'nugu' 15 -local dev
= 'plugin_under_development' 16 -local gh
= 'plugin_from_github' 17 -local srht
= 'plugin_from_srht' 18 -local cb
= 'plugin_from_codeberg' 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' 25 -local as_name = function ( plugin_coords )
26 - return vim.fs.basename(plugin_coords):gsub(
'(%w+)%.?%w*',
'%1' )
29 -local download_plugin_into = function ( plugin_name, 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 - local tmp_dir
= vim.uv.fs_mkdtemp(vim.fs.joinpath(vim.uv.os_tmpdir(),
'puck_tmp_install_path_XXXXXX'))
37 - local tarball_data_stream
= vim.uv.new_pipe(
true)
38 - local error_stream
= vim.uv.new_pipe()
40 - vim.uv.read_start(error_stream,
function(err, data)
41 - assert(
not err, err)
42 - if data
then vim.notify(data, vim.log.levels.ERROR)
end 45 - local curl_handle, curl_pid
= vim.uv.spawn(
'curl',
47 - args = {
'--silent',
'--location', plugin_tarball_url },
49 - stdio = {
nil, tarball_data_stream, error_stream},
56 - local tar_handle, tar_pid
= vim.uv.spawn(
'tar',
58 - args = {
'--extract',
'--gzip',
'--file',
'-' },
60 - stdio = { tarball_data_stream,
nil, error_stream},
72 - local extracted_dir
= vim.fs.find(
73 - function(name, path)
return name:find(plugin_name,
0,
true)
end,
74 - {
path = tmp_dir,
type =
'directory',
limit =
1 }
76 - vim.print(vim.inspect(extracted_dir))
77 - assert(
#extracted_dir
~= 0,
'No directory was found in tarball')
78 - assert(
#extracted_dir
== 1,
'Too many directories were found in tarball. Expected one!')
80 - local ok
= vim.fn.rename(extracted_dir[
1], plugin_install_path)
82 - assert(ok,
string.
format(
'Failed to move extracted plugin from %s to %s.', extracted_dir[
1], plugin_install_path))
84 - vim.uv.shutdown(tarball_data_stream,
function()
85 - vim.uv.close(curl_handle,
function()
86 - vim.print(
"curl closed")
88 - vim.uv.close(tar_handle,
function()
89 - vim.print(
"tar closed")
94 -local delete_directory_recursive = function ( path )
95 - local stat
= vim.uv.fs_stat( path )
96 - if stat
and stat.type
== 'directory' then 97 - local dir
= vim.uv.fs_scandir( path )
100 - local name,
type = vim.uv.fs_scandir_next( dir )
105 - local full_path
= vim.fs.joinpath( path, name )
106 - if type == 'directory' then 107 - return delete_directory_recursive( full_path )
109 - return vim.uv.fs_unlink( full_path )
113 - return vim.uv.fs_rmdir( 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 127 - error(
'unknown plugin type '..plugin_type
..' given.')
130 -local install_plugin = function ( puck_root, plugin_type, plugin_coords, plugin_rev )
131 - local plugin_name
= as_name( plugin_coords )
132 - local plugin_install_path
= vim.fs.normalize( vim.fs.joinpath( puck_root, plugin_name ) )
133 - local plugin_install_path_stat
= vim.uv.fs_stat( plugin_install_path )
134 - 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' ))
139 - if (vim.uv.fs_access( plugin_install_rev_path,
'R' ))
then 140 - 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 142 - local current_rev
= plugin_install_rev_file:read()
143 - plugin_install_rev_file:close()
144 - if current_rev
== plugin_rev
then return end 147 - local removed
= delete_directory_recursive( plugin_install_path )
148 - local url_format
= as_url_format(plugin_type)
149 - local plugin_tarball_url
= url_format:format( plugin_coords, plugin_rev )
150 - local ok
= pcall( download_plugin_into, plugin_name, plugin_tarball_url, plugin_install_path )
152 - local mode
= vim.uv.fs_access(plugin_install_rev_path,
'W')
and 'w+' or 'w' 153 - local plugin_install_rev_file
= io.
open( plugin_install_rev_path, mode)
154 - if not plugin_install_rev_file
then vim.notify(
'Unable to write rev file ' .. plugin_install_rev_path, vim.log.levels.ERROR)
end 155 - plugin_install_rev_file:write( plugin_rev )
156 - plugin_install_rev_file:close()
158 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' updated!', vim.log.levels.INFO )
160 - vim.notify(
'Plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. ' installed!', vim.log.levels.INFO )
163 - vim.notify(
'Failed to download tarball for plugin ' .. plugin_coords
.. '@' .. plugin_rev
.. '!',
164 - vim.log.levels.ERROR )
168 -local delete_unused_plugins = function ( puck_root )
end 170 -local register_local_plugin = function ( workspace, plugin_coords )
171 - local plugin_path
= vim.fs.normalize( vim.fs.joinpath(workspace, vim.fs.basename(plugin_coords) ) )
172 - local plugin_path_stat
= vim.uv.fs_stat( plugin_path )
174 - if (plugin_path_stat
and plugin_path_stat.type
== 'directory')
then 175 - vim.opt.runtimepath:prepend( plugin_path )
177 - vim.notify(
'Failed to load local plugin ' .. plugin_path
.. '!', vim.log.levels.ERROR )
181 -local load_local_plugin = function ( plugin_coords )
182 - local plugin_name
= as_name( plugin_coords )
183 - local plugin_init
= {}
184 - vim.tbl_extend(
'keep', plugin_init, vim.api.nvim_get_runtime_file(
'plugin/' .. plugin_name
.. '.vim',
false ) )
185 - vim.tbl_extend(
'keep', plugin_init, vim.api.nvim_get_runtime_file(
'plugin/' .. plugin_name
.. '.lua',
false ) )
186 - for _, init
in pairs( plugin_init )
do 187 - vim.cmd.source( init )
191 -local load_registered_plugin = function ( plugin_name )
195 -local setup = function ( options )
196 - options
= options
or {}
197 - vim.validate { [
'options.workspace'] = { options.workspace,
'string'}}
199 - options.plugins
= options.plugins
or {}
200 - plugins
= options.plugins
203 - vim.opt.loadplugins
= false 205 - local puck_root
= vim.fs.normalize( vim.fn.stdpath
'data' .. '/site/pack/puck' )
206 - vim.fn.mkdir( puck_root,
'p' )
208 - for _, plugin
in pairs( plugins )
do 209 - local plugin_type
= plugin[
1]
210 - local plugin_coords
= plugin[
2]
211 - local plugin_rev
= plugin[
3]
212 - if plugin_type
== dev
then 213 - register_local_plugin(options.workspace, plugin_coords )
215 - install_plugin( puck_root, plugin_type, plugin_coords, plugin_rev )
219 - delete_unused_plugins( puck_root )
223 - load_local_plugin
'plugin/shada.vim' 224 - load_local_plugin
'plugin/tutor.vim' 225 - load_local_plugin
'plugin/spellfile.vim' 226 - load_local_plugin
'plugin/osc52.lua' 229 - load_local_plugin
'plugin/editorconfig.lua' 235 - { dev,
'bugabinga/venn.nvim', },
236 - { gh,
'nyoom-engineering/oxocarbon.nvim',
'c5846d10cbe4131cc5e32c6d00beaf59cb60f6a2', },
237 - { srht,
'~adigitoleo/haunt.nvim',
'e3e3c8f45663fed8225ba5efb0af00a2df14a736', },
238 - { cb,
'jthvai/lavender.nvim',
'a5187e6f4afe4b1f2fbcd0fe0bad34c40002ba48', },
239 - { dev,
'bugabinga/auto-dark-mode.nvim',
nil, },
241 -setup {
plugins = plugins,
workspace =
'~/Workspace'}
242 -load_registered_plugin
'oxocarbon' 243 -vim.cmd.colorscheme
'oxocarbon' 246 - load = load_registered_plugin,