├── .gitignore ├── stylua.toml ├── lua ├── spec │ ├── session_test_file │ ├── is_in_list_spec.lua │ ├── session_files_spec.lua │ └── sort_spec.lua └── nvim-possession │ ├── sorting.lua │ ├── ui.lua │ ├── config.lua │ ├── utils.lua │ └── init.lua ├── .pre-commit-config.yaml ├── .github └── workflows │ ├── panvimdoc.yml │ └── release.yml ├── LICENSE ├── README.md └── doc └── possession.txt /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /stylua.toml: -------------------------------------------------------------------------------- 1 | indent_type = "Tabs" 2 | indent_width = 4 3 | -------------------------------------------------------------------------------- /lua/spec/session_test_file: -------------------------------------------------------------------------------- 1 | cd ~/nvim-possession 2 | badd +15 lua/nvim-possession/init.lua 3 | badd +9 ~/nvim-possession/./lua/spec/session_files_spec.lua 4 | badd +4 ~/nvim-possession/./lua/nvim-possession/utils.lua 5 | argglobal 6 | %argdel 7 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/JohnnyMorganz/StyLua 3 | rev: v0.14.3 4 | hooks: 5 | - id: stylua 6 | - repo: local 7 | hooks: 8 | - id: unittest 9 | name: unittest 10 | entry: busted 11 | language: system 12 | args: [-C=lua] 13 | pass_filenames: false 14 | -------------------------------------------------------------------------------- /lua/spec/is_in_list_spec.lua: -------------------------------------------------------------------------------- 1 | describe("test matching is_in_list", function() 2 | local utils 3 | local s, l, r 4 | 5 | setup(function() 6 | utils = require("nvim-possession.utils") 7 | s = "lua" 8 | r = "rust" 9 | l = { "python", "lua", "go", "vim" } 10 | end) 11 | 12 | teardown(function() 13 | utils = nil 14 | end) 15 | 16 | it("positive match", function() 17 | assert.is_true(utils.is_in_list(s, l)) 18 | end) 19 | it("negative match", function() 20 | assert.is_false(utils.is_in_list(r, l)) 21 | end) 22 | end) 23 | -------------------------------------------------------------------------------- /lua/nvim-possession/sorting.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | ---sort sessions by last updated 4 | ---@param a table 5 | ---@param b table 6 | ---@return boolean 7 | M.time_sort = function(a, b) 8 | if a.mtime.sec ~= b.mtime.sec then 9 | return a.mtime.sec > b.mtime.sec 10 | end 11 | if a.mtime.nsec ~= b.mtime.nsec then 12 | return a.mtime.nsec > b.mtime.nsec 13 | end 14 | return M.alpha_sort(a, b) 15 | end 16 | 17 | ---sort sessions by name 18 | ---@param a table 19 | ---@param b table 20 | ---@return boolean 21 | M.alpha_sort = function(a, b) 22 | return a.name < b.name 23 | end 24 | 25 | return M 26 | -------------------------------------------------------------------------------- /lua/spec/session_files_spec.lua: -------------------------------------------------------------------------------- 1 | describe("test matching session files", function() 2 | local utils 3 | local test_file, session_files 4 | 5 | setup(function() 6 | utils = require("nvim-possession.utils") 7 | test_file = "spec/session_test_file" 8 | session_files = { 9 | "lua/nvim-possession/init.lua", 10 | "lua/spec/session_files_spec.lua", 11 | "lua/nvim-possession/utils.lua", 12 | } 13 | end) 14 | 15 | teardown(function() 16 | utils = nil 17 | end) 18 | 19 | it("positive match", function() 20 | assert.same(session_files, utils.session_files(test_file)) 21 | end) 22 | end) 23 | -------------------------------------------------------------------------------- /lua/spec/sort_spec.lua: -------------------------------------------------------------------------------- 1 | describe("test matching sorting functions", function() 2 | local sort 3 | local sessions, time_sorted_sessions 4 | 5 | setup(function() 6 | sort = require("nvim-possession.sorting") 7 | sessions = { 8 | { name = "aaa", mtime = { sec = 0, nsec = 1 } }, 9 | { name = "zzz", mtime = { sec = 0, nsec = 2 } }, 10 | } 11 | time_sorted_sessions = 12 | { { name = "zzz", mtime = { sec = 0, nsec = 2 } }, { name = "aaa", mtime = { sec = 0, nsec = 1 } } } 13 | end) 14 | 15 | teardown(function() 16 | sort = nil 17 | end) 18 | 19 | it("time sorting", function() 20 | table.sort(sessions, sort.time_sort) 21 | assert.same(time_sorted_sessions, sessions) 22 | end) 23 | end) 24 | -------------------------------------------------------------------------------- /.github/workflows/panvimdoc.yml: -------------------------------------------------------------------------------- 1 | name: panvimdoc 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - '**' 8 | paths: 9 | - "README.md" 10 | - "**.yml" 11 | 12 | jobs: 13 | docs: 14 | runs-on: ubuntu-latest 15 | name: pandoc to vimdoc 16 | permissions: 17 | contents: write 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v4 21 | - name: panvimdoc 22 | uses: kdheepak/panvimdoc@main 23 | with: 24 | vimdoc: possession 25 | version: "Neovim >= 0.8.0" 26 | demojify: true 27 | treesitter: true 28 | - uses: stefanzweifel/git-auto-commit-action@v4 29 | if: startsWith(github.ref, 'refs/heads/') 30 | with: 31 | commit_message: "docs: auto generate vim documentation" 32 | branch: ${{ github.ref_name }} 33 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | tags: 7 | - "v*.*.*" 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | name: Github release 13 | permissions: 14 | contents: write 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | with: 19 | ref: ${{ github.head_ref || github.ref }} 20 | - name: Release 21 | uses: softprops/action-gh-release@v1 22 | 23 | luarocks-release: 24 | runs-on: ubuntu-latest 25 | name: LuaRocks upload 26 | steps: 27 | - name: Checkout 28 | uses: actions/checkout@v4 29 | with: 30 | ref: ${{ github.head_ref || github.ref }} 31 | - name: LuaRocks Upload 32 | uses: nvim-neorocks/luarocks-tag-release@v2.1.0 33 | env: 34 | LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} 35 | with: 36 | dependencies: | 37 | fzf-lua 38 | copy_directories: | 39 | doc 40 | license: "MIT" 41 | -------------------------------------------------------------------------------- /lua/nvim-possession/ui.lua: -------------------------------------------------------------------------------- 1 | local utils = require("nvim-possession.utils") 2 | 3 | local builtin_ok, builtin = pcall(require, "fzf-lua.previewer.builtin") 4 | if not builtin_ok then 5 | return 6 | end 7 | 8 | --- extend fzf builtin previewer 9 | local M = {} 10 | M.session_previewer = builtin.base:extend() 11 | 12 | M.session_previewer.new = function(self, o, opts, fzf_win) 13 | M.session_previewer.super.new(self, o, opts, fzf_win) 14 | setmetatable(self, M.session_previewer) 15 | return self 16 | end 17 | 18 | M.session_previewer.populate_preview_buf = function(self, entry_str) 19 | local tmpbuf = self:get_tmp_buffer() 20 | local files = utils.session_files(self.opts.user_config.sessions.sessions_path .. entry_str) 21 | 22 | vim.api.nvim_buf_set_lines(tmpbuf, 0, -1, false, files) 23 | self:set_preview_buf(tmpbuf) 24 | self.win:update_preview_scrollbar() 25 | end 26 | 27 | M.session_previewer.gen_winopts = function(self) 28 | local new_winopts = { 29 | wrap = false, 30 | number = false, 31 | } 32 | return vim.tbl_extend("force", self.winopts, new_winopts) 33 | end 34 | return M 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Gennaro Tedesco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lua/nvim-possession/config.lua: -------------------------------------------------------------------------------- 1 | local sort = require("nvim-possession.sorting") 2 | 3 | local M = {} 4 | 5 | M.sessions = { 6 | sessions_path = vim.fn.stdpath("data") .. "/sessions/", 7 | sessions_variable = "session", 8 | sessions_icon = "📌", 9 | sessions_prompt = "sessions:", 10 | } 11 | 12 | ---@type boolean 13 | M.autoload = false 14 | ---@type boolean 15 | M.autoprompt = false 16 | ---@type boolean 17 | M.autosave = true 18 | M.autoswitch = { 19 | enable = false, 20 | exclude_ft = {}, 21 | } 22 | 23 | ---@type function 24 | M.save_hook = nil 25 | ---@type function 26 | M.post_hook = nil 27 | 28 | ---@class possession.Hls 29 | ---@field normal? string hl group bg session window 30 | ---@field preview_normal? string hl group bg preview window 31 | ---@field border? string hl group border session window 32 | ---@field preview_border? string hl group border preview window 33 | M.fzf_hls = { 34 | normal = "Normal", 35 | preview_normal = "Normal", 36 | border = "Constant", 37 | preview_border = "Constant", 38 | } 39 | 40 | ---@class possession.Winopts 41 | ---@field border? string Any of the options of nvim_win_open.border 42 | ---@field height? number Height of the fzf window 43 | ---@field width? number Width of the fzf window 44 | ---@field preview? table 45 | M.fzf_winopts = { 46 | title = " sessions 📌 ", 47 | title_pos = "center", 48 | border = "rounded", 49 | height = 0.5, 50 | width = 0.25, 51 | preview = { 52 | hidden = "nohidden", 53 | horizontal = "down:40%", 54 | }, 55 | } 56 | 57 | ---@class possession.Mapopts 58 | ---@field delete? string 59 | ---@field rename? string 60 | ---@field new? string 61 | M.mappings = { 62 | action_delete = "ctrl-x", 63 | action_rename = "ctrl-r", 64 | action_new = "ctrl-n", 65 | } 66 | 67 | ---@type function 68 | M.sort = sort.alpha_sort 69 | 70 | return M 71 | -------------------------------------------------------------------------------- /lua/nvim-possession/utils.lua: -------------------------------------------------------------------------------- 1 | local sort = require("nvim-possession.sorting") 2 | local M = {} 3 | 4 | ---return the list of available sessions 5 | ---@param user_config table 6 | ---@return table 7 | M.list_sessions = function(user_config, cwd) 8 | local sessions = {} 9 | for name, type in vim.fs.dir(user_config.sessions.sessions_path) do 10 | if type == "file" then 11 | local stat = vim.uv.fs_stat(user_config.sessions.sessions_path .. name) 12 | if stat then 13 | table.insert(sessions, { name = name, mtime = stat.mtime }) 14 | end 15 | end 16 | end 17 | table.sort(sessions, function(a, b) 18 | if type(user_config.sort) == "function" then 19 | return user_config.sort(a, b) 20 | else 21 | return sort.alpha_sort(a, b) 22 | end 23 | end) 24 | local session_names = {} 25 | for _, sess in ipairs(sessions) do 26 | if cwd then 27 | if M.is_in_cwd(sess.name, user_config) then 28 | table.insert(session_names, sess.name) 29 | end 30 | else 31 | table.insert(session_names, sess.name) 32 | end 33 | end 34 | return session_names 35 | end 36 | 37 | ---return the list of files in the session 38 | ---@param file string 39 | ---@return table 40 | M.session_files = function(file) 41 | if vim.fn.isdirectory(file) == 1 then 42 | return {} 43 | end 44 | local lines = {} 45 | local cwd, cwd_pat = "", "^cd%s*" 46 | local buf_pat = "^badd%s*%+%d+%s*" 47 | for line in io.lines(file) do 48 | if string.find(line, cwd_pat) then 49 | cwd = line:gsub("%p", "%%%1") 50 | end 51 | if string.find(line, buf_pat) then 52 | lines[#lines + 1] = line 53 | end 54 | end 55 | local buffers = {} 56 | for k, v in pairs(lines) do 57 | buffers[k] = v:gsub(buf_pat, ""):gsub(cwd:gsub("cd%s*", ""), ""):gsub("^/?%.?/", "") 58 | end 59 | return buffers 60 | end 61 | 62 | ---checks whether a session is contained in the cwd 63 | ---@param session string 64 | ---@param user_config table 65 | ---@return boolean 66 | M.is_in_cwd = function(session, user_config) 67 | local session_dir, dir_pat = "", "^cd%s*" 68 | for file, type in vim.fs.dir(user_config.sessions.sessions_path) do 69 | if type == "file" and file == session then 70 | for line in io.lines(user_config.sessions.sessions_path .. file) do 71 | if string.find(line, dir_pat) then 72 | session_dir = vim.uv.fs_realpath(vim.fs.normalize((line:gsub("cd%s*", "")))) 73 | if session_dir == vim.fn.getcwd() then 74 | return true 75 | end 76 | end 77 | end 78 | end 79 | end 80 | return false 81 | end 82 | 83 | ---check if an item is in a list 84 | ---@param value string 85 | ---@param list table 86 | ---@return boolean 87 | M.is_in_list = function(value, list) 88 | for _, v in pairs(list) do 89 | if v == value then 90 | return true 91 | end 92 | end 93 | return false 94 | end 95 | 96 | ---check if a session is loaded and save it automatically 97 | ---without asking for prompt 98 | ---@param config table 99 | M.autosave = function(config) 100 | local cur_session = vim.g[config.sessions.sessions_variable] 101 | if type(config.save_hook) == "function" then 102 | config.save_hook() 103 | end 104 | if cur_session ~= nil then 105 | vim.cmd.mksession({ args = { config.sessions.sessions_path .. cur_session }, bang = true }) 106 | end 107 | end 108 | 109 | ---before switching session perform the following: 110 | ---1) autosave current session 111 | ---2) save and close all modifiable buffers 112 | ---@param config table 113 | M.autoswitch = function(config) 114 | if vim.api.nvim_buf_get_name(0) ~= "" then 115 | vim.cmd.write() 116 | end 117 | M.autosave(config) 118 | vim.cmd([[silent! bufdo if expand('%') !=# '' | edit | endif]]) 119 | local buf_list = vim.tbl_filter(function(buf) 120 | return vim.api.nvim_buf_is_valid(buf) 121 | and vim.bo[buf].buflisted 122 | and vim.bo[buf].modifiable 123 | and not M.is_in_list(vim.bo[buf].filetype, config.autoswitch.exclude_ft) 124 | end, vim.api.nvim_list_bufs()) 125 | for _, buf in pairs(buf_list) do 126 | vim.cmd("bd " .. buf) 127 | end 128 | end 129 | 130 | return M 131 | -------------------------------------------------------------------------------- /lua/nvim-possession/init.lua: -------------------------------------------------------------------------------- 1 | local config = require("nvim-possession.config") 2 | local ui = require("nvim-possession.ui") 3 | local utils = require("nvim-possession.utils") 4 | 5 | local M = {} 6 | 7 | ---expose the following interfaces: 8 | ---require("nvim-possession").new() 9 | ---require("nvim-possession").list() 10 | ---require("nvim-possession").update() 11 | ---require("nvim-possession").status() 12 | ---@param user_opts table 13 | M.setup = function(user_opts) 14 | local user_config = vim.tbl_deep_extend("force", config, user_opts or {}) 15 | 16 | local notification_title = user_config.sessions.sessions_icon .. " nvim-possession" 17 | local fzf_ok, fzf = pcall(require, "fzf-lua") 18 | if not fzf_ok then 19 | vim.notify("fzf-lua required as dependency", vim.log.levels.WARN, { title = notification_title }) 20 | return 21 | end 22 | 23 | ---get global variable with session name: useful for statusbar components 24 | ---@return string|nil 25 | M.status = function() 26 | local cur_session = vim.g[user_config.sessions.sessions_variable] 27 | return cur_session ~= nil and user_config.sessions.sessions_icon .. cur_session or nil 28 | end 29 | 30 | ---save current session if session path exists 31 | ---return if path does not exist 32 | M.new = function() 33 | if vim.fn.finddir(user_config.sessions.sessions_path) == "" then 34 | vim.notify("sessions_path does not exist", vim.log.levels.WARN, { title = notification_title }) 35 | return 36 | end 37 | 38 | local name = vim.fn.input("name: ") 39 | if name ~= "" then 40 | if next(vim.fs.find(name, { path = user_config.sessions.sessions_path })) == nil then 41 | vim.cmd.mksession({ args = { user_config.sessions.sessions_path .. name } }) 42 | vim.g[user_config.sessions.sessions_variable] = vim.fs.basename(name) 43 | vim.notify( 44 | "saved in: " .. user_config.sessions.sessions_path .. name, 45 | vim.log.levels.INFO, 46 | { title = notification_title } 47 | ) 48 | else 49 | vim.notify("session already exists", vim.log.levels.INFO, { title = notification_title }) 50 | end 51 | end 52 | end 53 | fzf.config.set_action_helpstr(M.new, "new-session") 54 | 55 | ---update loaded session with current status 56 | M.update = function() 57 | local cur_session = vim.g[user_config.sessions.sessions_variable] 58 | if cur_session ~= nil then 59 | local confirm = vim.fn.confirm("overwrite session?", "&Yes\n&No", 2) 60 | if confirm == 1 then 61 | if type(user_config.save_hook) == "function" then 62 | user_config.save_hook() 63 | end 64 | vim.cmd.mksession({ args = { user_config.sessions.sessions_path .. cur_session }, bang = true }) 65 | vim.notify("updated session: " .. cur_session, vim.log.levels.INFO, { title = notification_title }) 66 | end 67 | else 68 | vim.notify("no session loaded", vim.log.levels.INFO, { title = notification_title }) 69 | end 70 | end 71 | 72 | ---load selected session 73 | ---@param selected string 74 | M.load = function(selected) 75 | local session = user_config.sessions.sessions_path .. selected[1] 76 | if user_config.autoswitch.enable and vim.g[user_config.sessions.sessions_variable] ~= nil then 77 | utils.autoswitch(user_config) 78 | end 79 | vim.cmd.source(session) 80 | vim.g[user_config.sessions.sessions_variable] = vim.fs.basename(session) 81 | if type(user_config.post_hook) == "function" then 82 | user_config.post_hook() 83 | end 84 | end 85 | fzf.config.set_action_helpstr(M.load, "load-session") 86 | 87 | ---delete selected session 88 | ---@param selected string 89 | M.delete_selected = function(selected) 90 | local session = user_config.sessions.sessions_path .. selected[1] 91 | local confirm = vim.fn.confirm("delete session?", "&Yes\n&No", 2) 92 | if confirm == 1 then 93 | os.remove(session) 94 | vim.notify("deleted " .. session, vim.log.levels.INFO, { title = notification_title }) 95 | if vim.g[user_config.sessions.sessions_variable] == vim.fs.basename(session) then 96 | vim.g[user_config.sessions.sessions_variable] = nil 97 | end 98 | end 99 | end 100 | fzf.config.set_action_helpstr(M.delete_selected, "delete-session") 101 | 102 | ---delete current active session 103 | M.delete = function() 104 | local cur_session = vim.g[user_config.sessions.sessions_variable] 105 | if cur_session ~= nil then 106 | local confirm = vim.fn.confirm("delete session " .. cur_session .. "?", "&Yes\n&No", 2) 107 | if confirm == 1 then 108 | local session_path = user_config.sessions.sessions_path .. cur_session 109 | os.remove(session_path) 110 | vim.notify("deleted " .. session_path, vim.log.levels.INFO, { title = notification_title }) 111 | if vim.g[user_config.sessions.sessions_variable] == vim.fs.basename(session_path) then 112 | vim.g[user_config.sessions.sessions_variable] = nil 113 | end 114 | end 115 | else 116 | vim.notify("no active session", vim.log.levels.WARN, { title = notification_title }) 117 | end 118 | end 119 | 120 | ---rename selected session 121 | ---@param selected string 122 | M.rename_selected = function(selected) 123 | local session_path = user_config.sessions.sessions_path 124 | local old_name = selected[1] 125 | local old_file_path = session_path .. old_name 126 | local new_name = vim.fn.input("Enter new name for the session: ", old_name) 127 | 128 | if new_name and new_name ~= "" then 129 | local new_file_path = session_path .. new_name 130 | os.rename(old_file_path, new_file_path) 131 | vim.notify( 132 | "Session renamed from " .. old_name .. " to " .. new_name, 133 | vim.log.levels.INFO, 134 | { title = notification_title } 135 | ) 136 | else 137 | vim.notify("New name cannot be empty", vim.log.levels.WARN, { title = notification_title }) 138 | end 139 | end 140 | fzf.config.set_action_helpstr(M.rename_selected, "rename-session") 141 | 142 | ---list all existing sessions and their files 143 | ---@param cwd boolean|nil 144 | M.list = function(cwd) 145 | local iter = vim.uv.fs_scandir(user_config.sessions.sessions_path) 146 | if iter == nil then 147 | vim.notify( 148 | "session folder " .. user_config.sessions.sessions_path .. " does not exist", 149 | vim.log.levels.WARN, 150 | { title = notification_title } 151 | ) 152 | return 153 | end 154 | local next_dir = vim.uv.fs_scandir_next(iter) 155 | if next_dir == nil then 156 | vim.notify("no saved sessions", vim.log.levels.WARN, { title = notification_title }) 157 | return 158 | end 159 | 160 | local opts = { 161 | user_config = user_config, 162 | prompt = user_config.sessions.sessions_icon .. user_config.sessions.sessions_prompt, 163 | cwd_prompt = false, 164 | file_icons = false, 165 | git_icons = false, 166 | cwd_header = false, 167 | no_header = true, 168 | 169 | previewer = ui.session_previewer, 170 | hls = user_config.fzf_hls, 171 | winopts = user_config.fzf_winopts, 172 | cwd = user_config.sessions.sessions_path, 173 | actions = { 174 | ["enter"] = M.load, 175 | [user_config.mappings.action_delete] = { 176 | fn = function(selected) 177 | M.delete_selected(selected) 178 | M.list() 179 | end, 180 | header = "delete session", 181 | desc = "delete-session", 182 | }, 183 | [user_config.mappings.action_rename] = { 184 | fn = function(selected) 185 | M.rename_selected(selected) 186 | M.list() 187 | end, 188 | header = "rename session", 189 | desc = "rename-session", 190 | }, 191 | [user_config.mappings.action_new] = { fn = M.new, header = "new session", desc = "new-session" }, 192 | }, 193 | } 194 | opts = require("fzf-lua.config").normalize_opts(opts, {}) 195 | opts = require("fzf-lua.core").set_header(opts) 196 | 197 | ---autoload mechanism 198 | if cwd then 199 | local sessions_in_cwd = utils.list_sessions(user_config, cwd) 200 | if next(sessions_in_cwd) == nil then 201 | return nil 202 | elseif #sessions_in_cwd == 1 or not user_config.autoprompt then 203 | vim.schedule(function() 204 | vim.cmd.source(user_config.sessions.sessions_path .. sessions_in_cwd[1]) 205 | vim.g[user_config.sessions.sessions_variable] = vim.fs.basename(sessions_in_cwd[1]) 206 | if type(user_config.post_hook) == "function" then 207 | user_config.post_hook() 208 | end 209 | end) 210 | return nil 211 | end 212 | end 213 | ---standard list load mechanism 214 | fzf.fzf_exec(function(fzf_cb) 215 | for _, sess in ipairs(utils.list_sessions(user_config, cwd)) do 216 | fzf_cb(sess) 217 | end 218 | fzf_cb() 219 | end, opts) 220 | end 221 | 222 | if user_config.autoload and vim.fn.argc() == 0 then 223 | M.list(true) 224 | end 225 | 226 | if user_config.autosave then 227 | local autosave_possession = vim.api.nvim_create_augroup("AutosavePossession", {}) 228 | vim.api.nvim_clear_autocmds({ group = autosave_possession }) 229 | vim.api.nvim_create_autocmd("VimLeave", { 230 | group = autosave_possession, 231 | desc = "📌 save session on VimLeave", 232 | callback = function() 233 | utils.autosave(user_config) 234 | end, 235 | }) 236 | end 237 | end 238 | 239 | return M 240 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
4 |
234 |
235 |