Only load obsidian if we have at least one workspace

This commit is contained in:
Thomas Avé 2024-03-11 14:11:17 +01:00
parent c348b80b9f
commit 8f70e5e8a1
1 changed files with 5 additions and 1 deletions

View File

@ -20,8 +20,10 @@ return {
config = function(_, opts) config = function(_, opts)
local notes_path = (os.getenv "HOME") .. "/Workspace/Notes" local notes_path = (os.getenv "HOME") .. "/Workspace/Notes"
local scan = require("plenary.scandir").scan_dir(notes_path, {add_dirs = true, depth = 1 }) local scan = require("plenary.scandir").scan_dir(notes_path, {add_dirs = true, depth = 1 })
local found = false
for _, v in ipairs(scan) do for _, v in ipairs(scan) do
local subdir = v:match("([^/]+)$") local subdir = v:match("([^/]+)$")
found = true
if vim.fn.isdirectory(notes_path .. "/" .. subdir .. "/.obsidian") == 1 then if vim.fn.isdirectory(notes_path .. "/" .. subdir .. "/.obsidian") == 1 then
table.insert(opts.workspaces, { table.insert(opts.workspaces, {
name = subdir, name = subdir,
@ -34,7 +36,9 @@ return {
}) })
end end
end end
require("obsidian").setup(opts) if found then
require("obsidian").setup(opts)
end
end, end,
opts = { opts = {
workspaces = {}, workspaces = {},