From 337ac10adf0de2a4f63a742e1dc7a53fab12e880 Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Mon, 26 Aug 2024 20:46:38 -0700 Subject: [PATCH 1/2] fix: don't create empty extra command files --- lua/auto-session/init.lua | 2 +- lua/auto-session/lib.lua | 6 +++--- tests/cmds_spec.lua | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/auto-session/init.lua b/lua/auto-session/init.lua index 2fc68de..afaca64 100644 --- a/lua/auto-session/init.lua +++ b/lua/auto-session/init.lua @@ -344,7 +344,7 @@ end ---@private ---Get the hook commands from the config and run them ---@param hook_name string ----@return table Results of the commands +---@return table|nil Results of the commands function AutoSession.run_cmds(hook_name) local cmds = Config[hook_name .. "_cmds"] return Lib.run_hook_cmds(cmds, hook_name) diff --git a/lua/auto-session/lib.lua b/lua/auto-session/lib.lua index 643b2d4..1d0210a 100644 --- a/lua/auto-session/lib.lua +++ b/lua/auto-session/lib.lua @@ -536,13 +536,13 @@ end ---@param cmds table Cmds to run ---@param hook_name string Name of the hook being run ----@return table Results of the cmds +---@return table|nil Results of the cmds function Lib.run_hook_cmds(cmds, hook_name) - local results = {} if Lib.is_empty_table(cmds) then - return results + return nil end + local results = {} for _, cmd in ipairs(cmds) do Lib.logger.debug(string.format("Running %s command: %s", hook_name, cmd)) local success, result diff --git a/tests/cmds_spec.lua b/tests/cmds_spec.lua index cda4f8f..48b7f54 100644 --- a/tests/cmds_spec.lua +++ b/tests/cmds_spec.lua @@ -30,6 +30,10 @@ describe("The default config", function() -- Make sure the session has our buffer TL.assertSessionHasFile(TL.default_session_path, TL.test_file) assert.True(as.session_exists_for_cwd()) + + -- Make sure there isn't an extra commands file by default + local default_extra_cmds_path = TL.default_session_path:gsub("%.vim$", "x.vim") + assert.equals(0, vim.fn.filereadable(default_extra_cmds_path)) end) it("can restore a session for the cwd", function() From ab5f31136e149054734e58a3e599e1508f0fe12e Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Mon, 26 Aug 2024 21:12:05 -0700 Subject: [PATCH 2/2] fix: #300 sort picker by newest Also, removing fd and fdfind as we just need a simple directory listing. Keeping ripgrep because having one command that's consistent cross platform is nice. --- lua/auto-session/session-lens/init.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lua/auto-session/session-lens/init.lua b/lua/auto-session/session-lens/init.lua index d8bc0d6..a727a82 100644 --- a/lua/auto-session/session-lens/init.lua +++ b/lua/auto-session/session-lens/init.lua @@ -125,15 +125,11 @@ SessionLens.search_session = function(custom_opts) end return opts.find_command elseif 1 == vim.fn.executable "rg" then - return { "rg", "--files", "--color", "never" } - elseif 1 == vim.fn.executable "fd" then - return { "fd", "--type", "f", "--color", "never" } - elseif 1 == vim.fn.executable "fdfind" then - return { "fdfind", "--type", "f", "--color", "never" } - elseif 1 == vim.fn.executable "ls" and vim.fn.has "win32" == 0 then - return { "ls" } + return { "rg", "--files", "--color", "never", "--sortr", "modified" } + elseif 1 == vim.fn.executable "ls" then + return { "ls", "-t" } elseif 1 == vim.fn.executable "cmd" and vim.fn.has "win32" == 1 then - return { "cmd", "/C", "dir", "/b" } + return { "cmd", "/C", "dir", "/b", "/o-d" } end end)()