@@ -223,5 +223,50 @@ return {
223223 },
224224 },
225225 {
226+ ' olimorris/persisted.nvim' ,
227+ event = ' BufReadPre' , -- Ensure the plugin loads only when a buffer has been loaded
228+ keys = {
229+ { ' <leader>sp' , ' <Cmd>Telescope persisted<CR>' , desc = ' [S]earch [P]roject' },
230+ },
231+ config = function ()
232+ local utils = require ' persisted.utils'
233+ local allowed_dirs = {
234+ ' ~/.local/src' ,
235+ }
236+ require (' persisted' ).setup {
237+ should_save = function ()
238+ return utils .dirs_match (vim .fn .getcwd (), allowed_dirs )
239+ end ,
240+ use_git_branch = true ,
241+ }
242+ require (' telescope' ).setup {
243+ extensions = {
244+ persisted = {
245+ initial_mode = ' normal' ,
246+ },
247+ },
248+ }
249+ pcall (require (' telescope' ).load_extension ' persisted' )
250+
251+ vim .opt .sessionoptions :append ' globals'
252+ vim .api .nvim_create_autocmd ({ ' User' }, {
253+ pattern = ' PersistedSavePre' ,
254+ group = vim .api .nvim_create_augroup (' PersistedHooks' , {}),
255+ callback = function ()
256+ vim .api .nvim_exec_autocmds (' User' , { pattern = ' SessionSavePre' })
257+ end ,
258+ })
259+
260+ vim .api .nvim_create_autocmd (' User' , {
261+ pattern = ' PersistedTelescopeLoadPre' ,
262+ callback = function (session )
263+ -- Save the currently loaded session passing in the path to the current session
264+ require (' persisted' ).save { session = vim .g .persisted_loaded_session }
265+
266+ -- Delete all of the open buffers
267+ vim .api .nvim_input ' <ESC>:%bd!<CR>'
268+ end ,
269+ })
270+ end ,
226271 },
227272}
0 commit comments