From aa3cf0826222da2fd10e7103a8d1df53f30555ef Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 8 Jan 2025 11:41:31 -0800 Subject: [PATCH] Make default startify bookmarks dynamic Check for existing directories before adding --- neovim/lua/lazy_plugins.lua | 4 ++++ neovim/lua/plugins/startify.lua | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/neovim/lua/lazy_plugins.lua b/neovim/lua/lazy_plugins.lua index 1878bce..bf3e2d2 100644 --- a/neovim/lua/lazy_plugins.lua +++ b/neovim/lua/lazy_plugins.lua @@ -209,6 +209,10 @@ return { config = function() require("utils").require_with_local("plugins.startify") end, + dependencies = { + -- Plenary isn't used by startify, but it is used in my config + { "https://github.com/nvim-lua/plenary.nvim" }, + }, }, -- LSP diff --git a/neovim/lua/plugins/startify.lua b/neovim/lua/plugins/startify.lua index acf3b77..b2e2bad 100644 --- a/neovim/lua/plugins/startify.lua +++ b/neovim/lua/plugins/startify.lua @@ -9,10 +9,26 @@ vim.g.startify_list_order = { "sessions", } -vim.g.startify_bookmarks = { - "~/Documents/Obsidian", - "~/workspace/vim-settings", - "~/workspace/shoestrap", - "~/.config/fish", - "~/Nextcloud/Notes", -} +local function get_bookmarks() + local Path = require("plenary.path") + + local paths = { + "~/Documents/Obsidian", + "~/workspace/vim-settings", + "~/workspace/shoestrap", + "~/.config/fish", + "~/Nextcloud/Notes", + } + + local bookmarks = {} + for _, p in ipairs(paths) do + local path = Path:new(vim.fn.expand(p)) + if path:exists() then + table.insert(bookmarks, p) + end + end + + return bookmarks +end + +vim.g.startify_bookmarks = get_bookmarks()