From c348b80b9f84aa7920401961aa5e645854acb02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Mon, 11 Mar 2024 14:09:12 +0100 Subject: [PATCH] Dynamic finding of note workspaces --- nvim/lua/plugins/obsidian.lua | 64 +++++++++++++---------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/nvim/lua/plugins/obsidian.lua b/nvim/lua/plugins/obsidian.lua index 7cd2ec2..01dba0e 100644 --- a/nvim/lua/plugins/obsidian.lua +++ b/nvim/lua/plugins/obsidian.lua @@ -17,45 +17,31 @@ return { version = "*", -- recommended, use latest release instead of latest commit lazy = false, dependencies = { "nvim-lua/plenary.nvim" }, + config = function(_, opts) + local notes_path = (os.getenv "HOME") .. "/Workspace/Notes" + local scan = require("plenary.scandir").scan_dir(notes_path, {add_dirs = true, depth = 1 }) + for _, v in ipairs(scan) do + local subdir = v:match("([^/]+)$") + if vim.fn.isdirectory(notes_path .. "/" .. subdir .. "/.obsidian") == 1 then + table.insert(opts.workspaces, { + name = subdir, + path = notes_path .. "/" .. subdir, + overrides = { + daily_notes = { + folder = "Daily", + }, + }, + }) + end + end + require("obsidian").setup(opts) + end, opts = { - workspaces = { - { - name = "Lumentis", - path = "~/Workspace/Notes/Lumentis", - }, - { - name = "Lumentis-Players", - path = "~/Workspace/Notes/Lumentis-Players", - }, - { - name = "Personal", - path = "~/Workspace/Notes/Personal", - overrides = { - daily_notes = { - folder = "Daily", - }, - }, - }, - { - name = "PhD", - path = "~/Workspace/Notes/PhD", - overrides = { - daily_notes = { - folder = "Daily", - }, - }, - }, - { - name = "DnD", - path = "~/Workspace/Notes/DnD", - override = { - daily_notes = { - folder = ".", - }, - }, - }, - }, + workspaces = {}, note_id_func = function(title) return title end, + daily_notes = { + folder = "." + }, disable_frontmatter = true, ui = { hl_groups = { @@ -63,6 +49,7 @@ return { } } }, + keys = { {"", handle_enter, ft = "markdown" }, {"", "ObsidianLink", ft = "markdown", mode = "v"}, @@ -75,7 +62,4 @@ return { {"ju", "ObsidianTomorrow"}, {"", ":set nohlsearch/\\[[^\\[\\]]*\\]([^()]*):let @/ = \"\":set hlsearch", ft = "markdown", silent = true }, }, - config = function (_, opts) - require("obsidian").setup(opts) - end }