Skip to content

Commit

Permalink
Merge pull request #362 from cameronr/main
Browse files Browse the repository at this point in the history
fix: don't create empty extra command files
  • Loading branch information
cameronr authored Aug 27, 2024
2 parents f8ccc1b + ab5f311 commit 1568952
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lua/auto-session/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions lua/auto-session/session-lens/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)()

Expand Down
4 changes: 4 additions & 0 deletions tests/cmds_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1568952

Please sign in to comment.