From 6353af6d08b022924894fd242df8533a8992430b Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Thu, 8 Feb 2024 05:05:03 -0600 Subject: feat: add auto-session --- lua/plugins/auto-session.lua | 27 +++++++++++++++++++++++++++ lua/plugins/lualine.lua | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lua/plugins/auto-session.lua diff --git a/lua/plugins/auto-session.lua b/lua/plugins/auto-session.lua new file mode 100644 index 0000000..efbfef8 --- /dev/null +++ b/lua/plugins/auto-session.lua @@ -0,0 +1,27 @@ +return { + 'rmagatti/auto-session', + opts = { + log_level = 'error', + auto_session_enabled = true, + auto_session_create_enabled = false, + auto_save_enabled = false, -- i only want to save some sessions + auto_restore_enabled = true, -- always restore if session exists + -- handle closing the neotree window/buffer as it results in errors when loading the session + pre_save_cmds = { + function() + -- dirty way of handling neotree not being loaded yet (lazy load on nt) + local _ = pcall(vim.cmd, 'Neotree close') + end, + }, + }, + config = function(_, opts) + local ass = require('auto-session') + ass.setup(opts) + local sl = require('auto-session.session-lens') + + vim.keymap.set('n', 'asr', ass.RestoreSession, { desc = '[a]uto [s]ession: [r]estore' }) + vim.keymap.set('n', 'ass', ass.SaveSession, { desc = '[a]uto [s]ession: [s]ave' }) + vim.keymap.set('n', 'asd', ass.DeleteSession, { desc = '[a]uto [s]ession: [d]elete' }) + vim.keymap.set('n', 'asl', sl.search_session, { desc = '[a]uto [s]ession: [l]list' }) + end +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index c8c6377..3354031 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -2,6 +2,7 @@ return { 'nvim-lualine/lualine.nvim', dependencies = { { 'nvim-tree/nvim-web-devicons', opt = {} }, + 'rmagatti/auto-session', }, opts = { options = { @@ -12,7 +13,7 @@ return { }, sections = { lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_b = { require('auto-session.lib').current_session_name, 'branch', 'diff', 'diagnostics' }, lualine_c = { 'filename' }, lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_y = { 'progress' }, -- cgit v1.2.3-70-g09d2