Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't create empty extra command files #362

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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