nvim: add psoxizsh.entrypoint

these modules serve as the entrypoint for users to enter psoxizsh's
neovim configuration.
This commit is contained in:
Paul Stemmet 2024-08-08 12:28:34 +00:00
parent b17c56305c
commit f4cf1b75db
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
2 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,108 @@
---@class psoxizsh.entrypoint.config
local M = {}
---@class PsoxizshConfig
---@field profile string|PsoxizshConfigProfileCb|nil The stock profile to apply to the config
---@field keybinds PsoxizshConfigKeysCb|nil A callback to allow users to set the PsoxizshKeyBinds
---@field lazy LazyConfig|nil The configuration passed to our package manager
---@alias PsoxizshConfigKeysCb fun(keys: PsoxizshKeyBinds):nil
---@alias PsoxizshConfigProfileCb fun(config: PsoxizshConfig):nil
---Default PsoxizshConfig
---@return PsoxizshConfig
local defaults = function()
return {
lazy = {
spec = {
{ 'LazyVim/LazyVim',
import = 'lazyvim.plugins',
priority = 10000
},
{ 'psoxizsh',
import = 'psoxizsh.plugins',
priority = 09999,
dir = os.getenv('PSOXIZSH') .. '/nvim',
lazy = false,
opts = {},
config = function(_, opts) require('psoxizsh').setup(opts) end
},
{ import = 'plugins' },
},
defaults = {
lazy = false,
version = false,
keymaps = false,
},
install = {
colorscheme = {
'onedark', 'tokyonight', 'habamax',
}
},
checker = {
enabled = true,
concurrency = math.max(vim.uv.available_parallelism() - 2, 2),
frequency = 60 * 60 * 8, -- 8 hours
},
performance = {
rtp = {
disabled_plugins = {
-- 'gzip',
-- 'matchit',
-- 'matchparen',
'netrwPlugin',
-- 'tarPlugin',
'tohtml',
'tutor',
-- 'zipPlugin',
},
},
},
},
keybinds = function() --[[ don't override keybinds by default ]] end,
}
end
---Fetch the current PsoxizshConfig table
---@return PsoxizshConfig
function M.get()
if not M._lazy_config then
M._lazy_config = defaults()
end
return M._lazy_config
end
---Merge the given overrides into the current PsoxizshConfig
---@param overrides? PsoxizshConfig|PsoxizshConfigProfileCb
function M.set(overrides)
if type(overrides) == 'nil' then return end
if type(overrides) == 'function' then
M._lazy_config = overrides(M.get())
return
end
if type(overrides) == 'table' then
M._lazy_config = vim.tbl_deep_extend('force', M.get(), overrides)
return
end
vim.notify_once(
'config provided was neither a function or table, ignoring',
vim.log.levels.WARN,
{ title = 'psoxizsh.entrypoint' }
)
end
---Merge the given overrides into the current PsoxizshConfig, returning it
---@param overrides? PsoxizshConfig|PsoxizshConfigProfileCb
---@return PsoxizshConfig
function M.with(overrides)
M.set(overrides)
return M.get()
end
return M

View File

@ -0,0 +1,56 @@
---@class psoxizsh.entrypoint
local M = {}
local add_lazy_rtp = function()
if _G._psoxizsh_entrypoint_add_lazy_rtp == 1 then
return
end
vim.opt.rtp:prepend(os.getenv('PSOXIZSH') .. '/nvim/lazy.nvim')
_G._psoxizsh_entrypoint_add_lazy_rtp = 1
end
---Called the keybind callback, if any
---@param fn? PsoxizshConfigKeysCb
local set_keybinds = function(fn)
if type(fn) == 'function' then
fn(require('psoxizsh.key.binds'))
end
end
---Set the active profile (if any)
---@param profile? string|PsoxizshConfigProfileCb
---@param config PsoxizshConfig
local set_profile = function(profile, config)
if not profile then return end
if type(profile) == 'function' then
profile(config)
end
if type(profile) == 'string' then
if profile == 'psox' or profile == 'bazaah' then
require(('psoxizsh.entrypoint.profile.%s'):format(profile))(config)
end
end
end
---Begin Psoxizsh NeoVim initalization, with the default config
function M.start()
M.start_with(nil)
end
---Begin Psoxizsh NeoVim initalization with the given overrides
---@param overrides? PsoxizshConfig|PsoxizshConfigProfileCb
function M.start_with(overrides)
local config = require('psoxizsh.entrypoint.config').with(overrides)
add_lazy_rtp()
set_profile(config.profile, config)
set_keybinds(config.keybinds)
require('lazy').setup(config.lazy)
end
return M