From 6dd971b54192c4c70e9f78975fcf7965a893d4cd Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Wed, 4 Jun 2025 14:30:40 +0200 Subject: [PATCH] Adds automatic reopening --- .config/nvim/lua/functions/fs.lua | 17 +++++++++++++---- .config/nvim/lua/plugins/snacks_explorer.lua | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .config/nvim/lua/plugins/snacks_explorer.lua diff --git a/.config/nvim/lua/functions/fs.lua b/.config/nvim/lua/functions/fs.lua index 1ff1c10..6f7d6c3 100644 --- a/.config/nvim/lua/functions/fs.lua +++ b/.config/nvim/lua/functions/fs.lua @@ -1,12 +1,21 @@ local fs = {} -local function startswith(string, start) - return string:sub(1, #start) == start -end - function fs.getCurrentPath() local currentBuffer = vim.fn.expand("%") print(currentBuffer) end +function fs.getRootPath() + local initialArguments = vim.v.argv + local requestedFile = initialArguments[#initialArguments] + + local path = vim.fs.abspath(requestedFile) + + if vim.fn.isdirectory(path) == 1 then + return path + end + + return LazyVim.root() +end + return fs diff --git a/.config/nvim/lua/plugins/snacks_explorer.lua b/.config/nvim/lua/plugins/snacks_explorer.lua new file mode 100644 index 0000000..62aed93 --- /dev/null +++ b/.config/nvim/lua/plugins/snacks_explorer.lua @@ -0,0 +1,17 @@ +local fs = require("functions.fs") + +return { + "folke/snacks.nvim", + keys = { + { + "e", + function() + local rootdirectory = fs.getRootPath() + + Snacks.explorer({ cwd = rootdirectory }) + end, + desc = "Explorer Snacks (root directory)", + remap = true, + }, + }, +}