Skip to content

Commit 96c0630

Browse files
authored
Merge pull request #351 from cameronr/main
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
2 parents 322d82f + 7400bd8 commit 96c0630

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

doc/auto-session.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ session_lens_config *session_lens_config*
4848
{path_display?} (table) An array that specifies how to handle paths. Read :h telescope.defaults.path_display
4949
{theme_conf?} (table)
5050
{buftypes_to_ignore?} (table) Deprecated, if you're using this please report your usage on github
51-
{previewer?} (boolean)
51+
{previewer?} (boolean) Whether to show a preview of the session file (not very useful to most people)
5252
{session_control?} (session_control)
5353
{mappings?} (session_lens_mapping)
5454

lua/auto-session/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ local luaOnlyConf = {
108108
---@field path_display? table An array that specifies how to handle paths. Read :h telescope.defaults.path_display
109109
---@field theme_conf? table
110110
---@field buftypes_to_ignore? table Deprecated, if you're using this please report your usage on github
111-
---@field previewer? boolean
111+
---@field previewer? boolean Whether to show a preview of the session file (not very useful to most people)
112112
---@field session_control? session_control
113113
---@field mappings? session_lens_mapping
114114

@@ -125,6 +125,8 @@ local luaOnlyConf = {
125125
---@type session_lens_config
126126
session_lens = {
127127
load_on_setup = true,
128+
previewer = false,
129+
theme_conf = {},
128130
buftypes_to_ignore = {},
129131
session_control = {
130132
control_dir = vim.fn.stdpath "data" .. "/auto_session/", -- Auto session control dir, for control files, like alternating between two sessions with session-lens

lua/auto-session/lib.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ function Lib.current_session_name(tail_only)
2727
tail_only = tail_only or false
2828
-- get the filename without the extension
2929
local file_name = vim.fn.fnamemodify(vim.v.this_session, ":t:r")
30-
local session_name = Lib.get_session_display_name(file_name)
31-
3230
if not tail_only then
33-
return session_name
31+
return Lib.get_session_display_name(file_name)
32+
end
33+
34+
-- Have to get the display name sections if we want to shorten just the path in case
35+
-- there's a git branch
36+
local sections = Lib.get_session_display_name_as_table(file_name)
37+
sections[1] = vim.fn.fnamemodify(sections[1], ":t")
38+
if #sections == 1 then
39+
return sections[1]
3440
end
3541

36-
return vim.fn.fnamemodify(session_name, ":t")
42+
return table.concat(sections, " ")
3743
end
3844

3945
function Lib.is_empty_table(t)

tests/git_spec.lua

+19-9
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ describe("The git config", function()
1010

1111
TL.clearSessionFilesAndBuffers()
1212

13-
local git_test_dir = TL.tests_base_dir .. "/test_git"
13+
local git_test_dir = "test_git"
14+
local git_test_path = TL.tests_base_dir .. "/" .. git_test_dir
1415

15-
-- make test git dir
16-
if vim.fn.isdirectory(git_test_dir) ~= 1 then
17-
vim.fn.mkdir(git_test_dir)
18-
else
19-
TL.clearSessionFiles(git_test_dir)
20-
end
16+
-- clear git test dir
17+
vim.fn.delete(git_test_path, "rf")
18+
vim.fn.mkdir(git_test_path)
2119

2220
-- get a file in that dir
2321
vim.cmd("e " .. TL.test_file)
24-
vim.cmd("w! " .. git_test_dir .. "/test.txt")
22+
vim.cmd("w! " .. git_test_path .. "/test.txt")
2523
vim.cmd "%bw"
2624

2725
-- change to that dir
28-
vim.cmd("cd " .. git_test_dir)
26+
vim.cmd("cd " .. git_test_path)
2927

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

10098
assert.equals(vim.fn.getcwd() .. " (branch: main)", as.Lib.current_session_name())
10199
end)
100+
101+
it("can get the session name of a git branch with a slash", function()
102+
runCmdAndPrint "git checkout -b slash/branch"
103+
104+
as.SaveSession()
105+
106+
local session_path = TL.session_dir .. TL.escapeSessionName(vim.fn.getcwd() .. "|slash/branch") .. ".vim"
107+
assert.equals(1, vim.fn.filereadable(session_path))
108+
assert.equals(vim.fn.getcwd() .. " (branch: slash/branch)", as.Lib.current_session_name())
109+
assert.equals(git_test_dir .. " (branch: slash/branch)", as.Lib.current_session_name(true))
110+
print(as.Lib.current_session_name())
111+
end)
102112
end)

tests/lib_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,6 @@ describe("Lib / Helper functions", function()
181181
TL.clearSessionFilesAndBuffers()
182182

183183
assert.equals("", Lib.current_session_name())
184+
assert.equals("", Lib.current_session_name(true))
184185
end)
185186
end)

0 commit comments

Comments
 (0)