From 756824ccec891adffdc62e030cc1275433a4ef15 Mon Sep 17 00:00:00 2001 From: TropinoneH Date: Thu, 19 Dec 2024 21:58:50 +0800 Subject: [PATCH] feat: ask to remove non-existent session --- lua/persistence/init.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lua/persistence/init.lua b/lua/persistence/init.lua index 0f57b0e..e50c08a 100644 --- a/lua/persistence/init.lua +++ b/lua/persistence/init.lua @@ -103,6 +103,15 @@ function M.last() return M.list()[1] end +local function file_exists(path) + local ok, err, code = os.rename(path, path) + if code == 13 then + -- code 13 means permission denied, which is fine because it exists + return true + end + return ok +end + function M.select() ---@type { session: string, dir: string, branch?: string }[] local items = {} @@ -128,6 +137,17 @@ function M.select() end, }, function(item) if item then + local exist = file_exists(item.dir) + if not exist then + local confirm_code = vim.fn.confirm("Directory does not exist.\nWould you like to delete this session?", "&Yes\n&No") + if confirm_code == 0 or confirm_code == 2 then + return + end + if confirm_code == 1 then + vim.fn.delete(item.session) + return + end + end vim.fn.chdir(item.dir) M.load() end