@ -2,14 +2,8 @@
local config = require " core.config "
local common = require " core.common "
local core = require " core "
-- local system = require "system"
local os = require " os "
-- TODO: Add config support
-- Options:
-- keep_plugins: <bool> -- Whether to keep plugins installed after delinking them | DEFAULT: true
-- plugins: <table: <string>=<float/int> > -- List of enabled plugins
-- Stolen™ from gitstatus plugin (slightly modified)
local function exec ( cmd , opts )
local proc = process.start ( cmd , opts )
@ -19,24 +13,21 @@ local function exec(cmd, opts)
return proc : returncode ( )
end
local function dump ( o )
if type ( o ) == ' table ' then
local s = ' { '
for k , v in pairs ( o ) do
if type ( k ) ~= ' number ' then k = ' " ' .. k .. ' " ' end
s = s .. ' [ ' .. k .. ' ] = ' .. dump ( v ) .. ' , '
end
return s .. ' } '
else
return tostring ( o )
end
end
local dev_null = { stdout = process.REDIRECT_DISCARD ,
stderr = process.REDIRECT_DISCARD }
BULB_PLUGINS = USERDIR .. " /bulb-plugins/ "
-- function Set (list)
-- local set = {}
-- for _, l in ipairs(list) do set[l] = true end
-- return set
-- end
local function git ( subfunction , parameters )
os.execute ( " git " .. subfunction .. " " .. parameters or " " .. " >/dev/null 2>&1 " )
end
-- local function git(subfunction, parameters)
-- exec({"git", subfunction, parameters or ""},
-- { stdout = process.REDIRECT_DISCARD,
-- stderr = process.REDIRECT_DISCARD })
-- end
local function check_url ( url )
local good_url
@ -47,22 +38,18 @@ local function check_url(url)
good_url = " https://github.com/ " .. url
end
-- local url_exists = {os.execute("curl --head --silent --fail " .. good_url .. " >/dev/null 2>&1")}
local url_exists = exec ( { " curl " , " --head " , " --silent " , " --fail " , good_url } , { } )
if url_exists ~= 0 then
-- core.log(url_exists)
core.log ( dump ( url_exists ) )
-- core.log("curl --head --silent --fail " .. good_url .. " >/dev/null 2>&1")
core.error ( " Could not find plugin \" " .. good_url .. " \" , check if the identifier is correct " )
return " oopsy "
return nil
end
return good_url
end
config.plugins . bulb = common.merge ( {
keep_plugins = true ,
-- keep_plugins = true ,
-- plugins = {}
plugins = { " delta-official/lite-bulb " , " https://git.karx.xyz/delta/lite-bulb " , " https://git.karx.xyz/deez/nuts " } -- Format: <string>/{string + extra bs (see docs)} = <float/int>
} , config.plugins . bulb )
@ -70,62 +57,52 @@ config.plugins.bulb = common.merge({
-- So string is basically gonna have this format "<https://github.com/>username/repo<:FILE>"
-- where FILE is the file/list of files to symlink into plugins folder
core.add_thread ( function ( )
local git_installed = exec ( { " git " , " help " } ,
{ stdout = process.REDIRECT_DISCARD ,
stderr = process.REDIRECT_DISCARD } )
local git_installed = exec ( { " git " , " help " } , dev_null )
if git_installed ~= 0 then
core.error ( " git is not installed, please install git to use bulb " )
os.exit ( )
end
local curl_installed = exec ( { " curl " , " -h " } ,
{ stdout = process.REDIRECT_DISCARD ,
stderr = process.REDIRECT_DISCARD } )
if git_installed ~= 0 then
core.error ( " git is not installed. Please install git to use bulb " )
os.exit ( )
end
if curl_installed ~= 0 then
core.error ( " curl is not installed, please install curl to use bulb " )
os.exit ( )
end
local curl_installed = exec ( { " curl " , " -h " } , dev_null )
for _ , plugin in ipairs ( config.plugins . bulb.plugins ) do
if type ( plugin ) == " string " then
-- git("clone", "")
core.log ( plugin )
core.log ( check_url ( plugin ) )
if curl_installed ~= 0 then
core.error ( " curl is not installed. Please install curl to use bulb " )
os.exit ( )
end
elseif type ( plugin ) == " table " then
end
end
for _ , plugin in ipairs ( config.plugins . bulb.plugins ) do
local plugin_path = BULB_PLUGINS .. string.match ( url , " /([^/]+)$ " )
if type ( plugin ) == " string " then
local url = check_url ( plugin )
if url ~= nil then
exec ( { " git " , " clone " , url , plugin_path } , dev_null )
-- Fetch all repository tags
exec ( { " git " , " -C " , plugin_path , " fetch " , " --tags " } , dev_null )
end
elseif type ( plugin ) == " table " then
if plugin.version and plugin.commit then --
-- If both plugin version and commit are supplied prefer hash over version
-- Also warn user that this is a bad config
exec ( { " git " , " -C " , plugin_path , " checkout " , plugin.hash } , dev_null )
core.warn ( " Specifying both plugin version and hash for \" " .. plugin .. " \" . This is not supported. " )
elseif plugin.version then
-- switch to the specified version (tag)
exec ( { " git " , " -C " , plugin_path , " c " , plugin.version } , dev_null )
elseif plugin.hash then
-- switch to the specified version (commit)
exec ( { " git " , " -C " , plugin_path , " checkout " , plugin.commit } , dev_null )
end
end
-- Check if the bulb-plugins have any plugins not in the plugin list
for _ , installed_plugin in ipairs ( ) do
end
end
end )
local git_repo = " https://github.com/lite-xl/lite-xl-plugins "
-- local function exists(file)
-- local ok, err, code = os.rename(file, file)
-- if not ok then
-- if code == 13 then
-- -- Permission denied, but it exists
-- return true
-- end
-- end
-- return ok, err
-- end
-- if not exists
-- local bulb = {}
-- function bulb.validate_plugins()
-- for _, name in ipairs(config.plugins.bulb.plugins) do
-- end
-- end
---@param string plugin
-- function bulb(plugin)
-- end