1
1
local config = require (' session_manager.config' )
2
2
local scandir = require (' plenary.scandir' )
3
3
local Path = require (' plenary.path' )
4
- local utils = { is_session = false }
4
+ local utils = {}
5
5
6
6
--- A small wrapper around `vim.notify` that adds plugin title.
7
7
--- @param msg string
@@ -58,7 +58,6 @@ function utils.load_session(filename, discard_current)
58
58
59
59
local swapfile = vim .o .swapfile
60
60
vim .o .swapfile = false
61
- utils .is_session = true
62
61
vim .api .nvim_exec_autocmds (' User' , { pattern = ' SessionLoadPre' })
63
62
vim .api .nvim_command (' silent source ' .. filename )
64
63
vim .api .nvim_exec_autocmds (' User' , { pattern = ' SessionLoadPost' })
@@ -84,20 +83,13 @@ function utils.save_session(filename)
84
83
vim .api .nvim_command (' %argdel' )
85
84
end
86
85
87
- utils .is_session = true
88
86
vim .api .nvim_exec_autocmds (' User' , { pattern = ' SessionSavePre' })
89
87
vim .api .nvim_command (' mksession! ' .. filename )
90
88
vim .api .nvim_exec_autocmds (' User' , { pattern = ' SessionSavePost' })
91
89
end
92
90
93
91
--- @param filename string
94
- function utils .delete_session (filename )
95
- Path :new (filename ):rm ()
96
- local cwd = vim .uv .cwd ()
97
- if utils .is_session and cwd and filename == config .dir_to_session_filename (cwd ).filename then
98
- utils .is_session = false
99
- end
100
- end
92
+ function utils .delete_session (filename ) Path :new (filename ):rm () end
101
93
102
94
--- @param opts table ?: Additional arguments. Currently only ` silent` is supported.
103
95
--- @return table
@@ -114,7 +106,7 @@ function utils.get_sessions(opts)
114
106
table.sort (sessions , function (a , b ) return a .timestamp > b .timestamp end )
115
107
116
108
-- If we are in a session already, don't list the current session.
117
- if utils .is_session then
109
+ if utils .is_exist_in_session () then
118
110
local cwd = vim .uv .cwd ()
119
111
local is_current_session = cwd and config .dir_to_session_filename (cwd ).filename == sessions [1 ].filename
120
112
if is_current_session then
@@ -171,6 +163,17 @@ function utils.is_restorable_buffer_present()
171
163
return false
172
164
end
173
165
166
+ --- @return boolean
167
+ function utils .is_exist_in_session ()
168
+ local cwd = vim .uv .cwd ()
169
+ for _ , session_filename in ipairs (scandir .scan_dir (tostring (config .sessions_dir ))) do
170
+ if config .dir_to_session_filename (cwd ).filename == session_filename then
171
+ return true
172
+ end
173
+ end
174
+ return false
175
+ end
176
+
174
177
--- @return boolean
175
178
function utils .is_dir_in_ignore_list ()
176
179
local cwd = vim .uv .cwd ()
0 commit comments