marleyvim/nvim/lua/lib/init.lua

41 lines
1.1 KiB
Lua

---@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
---Generates a function that can be used to create which-key mappings.
---@param color string The color to use for the icon.
---@return function
function M.wkSpec(color)
---@param lhs string
---@param rhs string | fun()
---@param icon string | wk.Icon
---@param opts? wk.Spec
return function(lhs, rhs, icon, opts)
if type(icon) == 'string' then
icon = { icon = icon, color = color }
else
icon = vim.tbl_deep_extend('force', icon, { color = color })
end
return vim.tbl_deep_extend('force', { lhs, rhs, icon = icon }, (opts or {}))
end
end
return M