Skip to content

Commit 62671a7

Browse files
authored
feat(dirman): in_workspace function (#1615)
1 parent 0460ccd commit 62671a7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lua/neorg/modules/core/dirman/module.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module.public = {
162162
get_workspace = function(name)
163163
return module.config.public.workspaces[name]
164164
end,
165-
--- Returns a table in the format { "workspace_name", "path" }
165+
--- @return { [1]: string, [2]: PathlibPath }
166166
get_current_workspace = function()
167167
return module.private.current_workspace
168168
end,
@@ -472,6 +472,20 @@ module.public = {
472472
end)
473473
end
474474
end,
475+
476+
---Is the file a part of the given workspace?
477+
---@param file PathlibPath
478+
---@param workspace_name string? workspace or current ws when nil
479+
---@return boolean
480+
in_workspace = function(file, workspace_name)
481+
local ws_path
482+
if not workspace_name then
483+
ws_path = module.private.current_workspace[2]
484+
else
485+
ws_path = module.public.get_workspace(workspace_name)
486+
end
487+
return not not file:match("^" .. ws_path)
488+
end,
475489
}
476490

477491
module.on_event = function(event)

0 commit comments

Comments
 (0)