Skip to content

Commit

Permalink
Merge pull request #351 from cameronr/main
Browse files Browse the repository at this point in the history
fix: #349 Forgot to bring over the default session lens config values, fix #352 current_session_name incorrectly displayed if git branch has forward slash
  • Loading branch information
cameronr authored Aug 15, 2024
2 parents 322d82f + 7400bd8 commit 96c0630
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/auto-session.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ session_lens_config *session_lens_config*
{path_display?} (table) An array that specifies how to handle paths. Read :h telescope.defaults.path_display
{theme_conf?} (table)
{buftypes_to_ignore?} (table) Deprecated, if you're using this please report your usage on github
{previewer?} (boolean)
{previewer?} (boolean) Whether to show a preview of the session file (not very useful to most people)
{session_control?} (session_control)
{mappings?} (session_lens_mapping)

Expand Down
4 changes: 3 additions & 1 deletion lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ local luaOnlyConf = {
---@field path_display? table An array that specifies how to handle paths. Read :h telescope.defaults.path_display
---@field theme_conf? table
---@field buftypes_to_ignore? table Deprecated, if you're using this please report your usage on github
---@field previewer? boolean
---@field previewer? boolean Whether to show a preview of the session file (not very useful to most people)
---@field session_control? session_control
---@field mappings? session_lens_mapping

Expand All @@ -125,6 +125,8 @@ local luaOnlyConf = {
---@type session_lens_config
session_lens = {
load_on_setup = true,
previewer = false,
theme_conf = {},
buftypes_to_ignore = {},
session_control = {
control_dir = vim.fn.stdpath "data" .. "/auto_session/", -- Auto session control dir, for control files, like alternating between two sessions with session-lens
Expand Down
14 changes: 10 additions & 4 deletions lua/auto-session/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ function Lib.current_session_name(tail_only)
tail_only = tail_only or false
-- get the filename without the extension
local file_name = vim.fn.fnamemodify(vim.v.this_session, ":t:r")
local session_name = Lib.get_session_display_name(file_name)

if not tail_only then
return session_name
return Lib.get_session_display_name(file_name)
end

-- Have to get the display name sections if we want to shorten just the path in case
-- there's a git branch
local sections = Lib.get_session_display_name_as_table(file_name)
sections[1] = vim.fn.fnamemodify(sections[1], ":t")
if #sections == 1 then
return sections[1]
end

return vim.fn.fnamemodify(session_name, ":t")
return table.concat(sections, " ")
end

function Lib.is_empty_table(t)
Expand Down
28 changes: 19 additions & 9 deletions tests/git_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ describe("The git config", function()

TL.clearSessionFilesAndBuffers()

local git_test_dir = TL.tests_base_dir .. "/test_git"
local git_test_dir = "test_git"
local git_test_path = TL.tests_base_dir .. "/" .. git_test_dir

-- make test git dir
if vim.fn.isdirectory(git_test_dir) ~= 1 then
vim.fn.mkdir(git_test_dir)
else
TL.clearSessionFiles(git_test_dir)
end
-- clear git test dir
vim.fn.delete(git_test_path, "rf")
vim.fn.mkdir(git_test_path)

-- get a file in that dir
vim.cmd("e " .. TL.test_file)
vim.cmd("w! " .. git_test_dir .. "/test.txt")
vim.cmd("w! " .. git_test_path .. "/test.txt")
vim.cmd "%bw"

-- change to that dir
vim.cmd("cd " .. git_test_dir)
vim.cmd("cd " .. git_test_path)

local function runCmdAndPrint(cmd)
---@diagnostic disable-next-line: unused-local
Expand Down Expand Up @@ -99,4 +97,16 @@ describe("The git config", function()

assert.equals(vim.fn.getcwd() .. " (branch: main)", as.Lib.current_session_name())
end)

it("can get the session name of a git branch with a slash", function()
runCmdAndPrint "git checkout -b slash/branch"

as.SaveSession()

local session_path = TL.session_dir .. TL.escapeSessionName(vim.fn.getcwd() .. "|slash/branch") .. ".vim"
assert.equals(1, vim.fn.filereadable(session_path))
assert.equals(vim.fn.getcwd() .. " (branch: slash/branch)", as.Lib.current_session_name())
assert.equals(git_test_dir .. " (branch: slash/branch)", as.Lib.current_session_name(true))
print(as.Lib.current_session_name())
end)
end)
1 change: 1 addition & 0 deletions tests/lib_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@ describe("Lib / Helper functions", function()
TL.clearSessionFilesAndBuffers()

assert.equals("", Lib.current_session_name())
assert.equals("", Lib.current_session_name(true))
end)
end)

0 comments on commit 96c0630

Please sign in to comment.