45 lines
1.1 KiB
Lua
45 lines
1.1 KiB
Lua
local M = {}
|
|
|
|
function M.config()
|
|
local status_ok, session_manager = pcall(require, "session_manager")
|
|
if not status_ok then
|
|
return
|
|
end
|
|
|
|
local sm_config = require'session_manager.config'
|
|
local function get_branch_name()
|
|
local handle = io.popen("git branch --show-current 2>/dev/null")
|
|
if (handle == nil) then
|
|
return nil
|
|
end
|
|
local branch = handle:read("l")
|
|
handle:close()
|
|
if (branch == nil) then
|
|
return nil
|
|
end
|
|
branch = branch:gsub("/", "--")
|
|
return branch
|
|
end
|
|
|
|
-- 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)
|
|
local filename_without_extra = filename:sub(0, filename:find("=="))
|
|
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
|
|
return filename .. "==" .. branch
|
|
else
|
|
return filename
|
|
end
|
|
end,
|
|
})
|
|
end
|
|
|
|
return M
|
|
|