marleyvim/nvim/lua/lib/init.lua

42 lines
1.1 KiB
Lua
Raw Normal View History

---@class lib
local M = {}
---Find the root of a project based on `vim.g.root_spec`. Defaults to
---`{ '.git' }` if unset.
---@return string?
function M.root()
local root_spec = vim.g.root_spec or { '.git' }
return vim.fs.root(0, root_spec)
end
---Require a file relative to the given prefix, to avoid repetition.
---@param prefix string The string to prefix to all req calls.
function M.local_require(prefix)
---@param mod string The module to require.
return function(mod)
return require(prefix .. '.' .. mod)
end
end
2024-12-01 17:10:02 -08:00
---Generates a function that can be used to create which-key mappings.
---@param color string The color to use for the icon.
---@return function
2024-12-04 21:41:30 -08:00
function M.wkSpec(color)
2024-12-01 17:10:02 -08:00
---@param lhs string
2024-12-04 21:41:30 -08:00
---@param rhs string | fun()
2024-12-04 21:35:35 -08:00
---@param icon string | wk.Icon
2024-12-01 17:10:02 -08:00
---@param opts? wk.Spec
2024-12-04 21:41:30 -08:00
return function(lhs, rhs, icon, opts)
2024-12-04 21:35:35 -08:00
if type(icon) == 'string' then
icon = { icon = icon, color = color }
else
icon = vim.tbl_deep_extend('force', icon, { color = color })
end
2024-12-04 21:41:30 -08:00
return vim.tbl_deep_extend('force', { lhs, rhs, icon = icon }, (opts or {}))
2024-12-01 17:10:02 -08:00
end
end
return M