38 lines
962 B
Lua
38 lines
962 B
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 icon string
|
|
---@param opts? wk.Spec
|
|
return function(lhs, icon, opts)
|
|
return vim.tbl_deep_extend(
|
|
'force',
|
|
{ lhs, icon = { icon = icon, color = color } },
|
|
(opts or {})
|
|
)
|
|
end
|
|
end
|
|
|
|
return M
|