-local pickers = require "telescope.pickers"
-local finders = require "telescope.finders"
-local conf = require("telescope.config").values
-local actions = require "telescope.actions"
-local action_state = require "telescope.actions.state"
-
+local history_dir = vim.fn.stdpath("state") .."/sessionmanager/"
+local history_file = history_dir .."history.lua"
local history = {}
+-- serialize and write to disk
+local function serialize_to_disk()
+ local function serialize()
+ local str = ""
+ for _, entry in pairs(history) do
+ str = str .."Project { path = \"" ..entry.path .."\", timestamp = " ..(entry.timestamp or "nil") .." }\n"
+ end
+
+ return str
+ end
+
+ -- serialize history
+ local history_str = serialize()
+
+ -- write to disk
+ vim.fn.mkdir(history_dir, "p")
+ local f = assert(io.open(history_file, "w"))
+ f:write(history_str)
+ f:close()
+end
+
-- show session history in telescope
local function session_picker(opts)
opts = opts or require("telescope.themes").get_dropdown{}
return (a.timestamp or 0) > (b.timestamp or 0)
end)
+ local pickers = require "telescope.pickers"
+ local finders = require "telescope.finders"
+ local conf = require("telescope.config").values
+ local actions = require "telescope.actions"
+ local action_state = require "telescope.actions.state"
+
pickers.new(opts, {
prompt_title = "session history",
finder = finders.new_table {
-- determine new directory
local selection = action_state.get_selected_entry()
local entry = selection.value
+ local path = entry.path
+
+ -- update timestamp and serialize to disk
+ history[path].timestamp = os.time()
+ serialize_to_disk()
-- split window
local vsplit = require("snippets.vsplit")
- vsplit.reset{ path = entry.path, start_explorer = true }
+ vsplit.reset{ path = path, start_explorer = true }
end)
return true
end
-- read and update history file on disk
do
- local history_dir = vim.fn.stdpath("state") .."/sessionmanager/"
- local history_file = history_dir .."history.lua"
-
-- read history from disk
do
function Project(entry)
-- add current directory to history
do
- local function serialize()
- local str = ""
- for _, entry in pairs(history) do
- str = str .."Project { path = \"" ..entry.path .."\", timestamp = " ..(entry.timestamp or "nil") .." }\n"
- end
-
- return str
- end
-
local cwd = vim.fn.getcwd()
- local entry = { path = cwd, timestamp = os.time() }
- history[cwd] = entry
- -- serialize history
- local history_str = serialize()
-
- -- write to disk
- vim.fn.mkdir(history_dir, "p")
- local f = assert(io.open(history_file, "w"))
- f:write(history_str)
- f:close()
+ -- ignore home directory
+ if not ((cwd == vim.fn.expand("~")) or (cwd == vim.uv.os_homedir())) then
+ local entry = { path = cwd, timestamp = os.time() }
+ history[cwd] = entry
+ end
end
end