nvim-config/lua/configs/session-manager.lua

44 lines
1.1 KiB
Lua
Raw Normal View History

2022-10-26 17:03:13 +00:00
local M = {}
function M.config()
2023-01-10 18:21:09 +00:00
local status_ok, session_manager = pcall(require, 'session_manager')
2022-10-26 17:03:13 +00:00
if not status_ok then
return
end
2023-01-10 18:21:09 +00:00
local sm_config = require('session_manager.config')
2022-11-18 21:27:11 +00:00
local function get_branch_name()
2023-01-10 18:21:09 +00:00
local handle = io.popen('git branch --show-current 2>/dev/null')
if handle == nil then
2022-11-18 21:27:11 +00:00
return nil
end
2023-01-10 18:21:09 +00:00
local branch = handle:read('l')
2022-11-18 21:27:11 +00:00
handle:close()
2023-01-10 18:21:09 +00:00
if branch == nil then
2022-11-18 21:27:11 +00:00
return nil
end
2023-01-10 18:21:09 +00:00
branch = branch:gsub('/', '--')
2022-11-18 21:27:11 +00:00
return branch
end
2022-10-26 17:03:13 +00:00
2022-11-18 21:27:11 +00:00
-- this plugin saves sessions for the working directory automatically
session_manager.setup({
autoload_mode = sm_config.AutoloadMode.Disabled, -- do not auto-load the last session at startup
session_filename_to_dir = function(filename)
2023-01-10 18:21:09 +00:00
local filename_without_extra = filename:sub(0, filename:find('=='))
2022-11-18 21:27:11 +00:00
return sm_config.delimited_session_filename_to_dir(filename_without_extra)
end,
dir_to_session_filename = function(dir)
local filename = sm_config.dir_to_delimited_session_filename(dir)
local branch = get_branch_name()
if branch ~= nil then
2023-01-10 18:21:09 +00:00
return filename .. '==' .. branch
2022-11-18 21:27:11 +00:00
else
return filename
end
end,
})
2022-10-26 17:03:13 +00:00
end
return M