aboutsummaryrefslogtreecommitdiff
path: root/common/config/nvim/lua/plugins/auto-session.lua
blob: d982e08a7ee8038d147faf3693fd98792a9882d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local M = {}

function M.setup()
  local auto = pcall(require, 'auto-session') and require('auto-session')
  if not auto then
    return false
  end

  local nvim_version = vim.version()
  if nvim_version.major == 0 and nvim_version.minor < 5 then
    return false
  end

  -- Configure session options
  vim.opt.sessionoptions:append("localoptions")  -- Add localoptions to sessionoptions

  -- Set up auto-session
  auto.setup({
    log_level = 'info',
    auto_session_suppress_dirs = { '~/', '~/Projects', '~/projects', '~/Downloads', '~/downloads' },
    auto_session_use_git_branch = true,
    bypass_save_filetypes = { "dashboard" },

    -- Additional configuration to handle session options
    pre_save_cmds = {
      -- Ensure local options are saved with the session
      function() vim.opt.sessionoptions:append("localoptions") end,
    },

    -- Post restore hook to ensure local options are properly set
    post_restore = function()
      vim.opt.sessionoptions:append("localoptions")
    end,
  })

  return true
end

return M