diff --git a/README.md b/README.md index 6e05d16..afb385d 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,11 @@ require("persisted").setup({ copy_session = "", delete_session = "", }, + icons = { -- icons displayed in the picker, set to nil to disable entirely + branch = " ", + dir = " ", + selected = " ", + }, }, }) ``` diff --git a/doc/persisted.nvim.txt b/doc/persisted.nvim.txt index 1926eeb..483900a 100644 --- a/doc/persisted.nvim.txt +++ b/doc/persisted.nvim.txt @@ -169,6 +169,11 @@ The plugin comes with the following defaults: copy_session = "", delete_session = "", }, + icons = { -- icons displayed in the picker, set to nil to disable entirely + branch = " ", + dir = " ", + selected = " ", + }, }, }) < diff --git a/lua/persisted/config.lua b/lua/persisted/config.lua index fccd4d3..ac1c8d2 100644 --- a/lua/persisted/config.lua +++ b/lua/persisted/config.lua @@ -27,13 +27,18 @@ local defaults = { copy_session = "", delete_session = "", }, + icons = { -- icons displayed in the picker + branch = " ", + dir = " ", + selected = " ", + }, }, } M.options = {} function M.setup(opts) - M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {}) + M.options = vim.tbl_deep_extend("force", defaults, opts or {}) vim.fn.mkdir(M.options.save_dir, "p") end diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index e853d58..df4a884 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -367,11 +367,18 @@ function M.list() dir_path = session_name end + local f = io.popen("stat -f %a " .. session) + local last_modified = "" + if f then + last_modified = f:read() + end + table.insert(sessions, { ["name"] = session_name, ["file_path"] = session, ["branch"] = branch, ["dir_path"] = dir_path, + ["last_modified"] = last_modified, }) end diff --git a/lua/telescope/_extensions/persisted.lua b/lua/telescope/_extensions/persisted.lua index b1723cd..6ca3d9b 100644 --- a/lua/telescope/_extensions/persisted.lua +++ b/lua/telescope/_extensions/persisted.lua @@ -53,6 +53,9 @@ end return require("telescope").register_extension({ setup = function(topts) + vim.api.nvim_set_hl(0, "TelescopePersistedIsCurrent", { link = "TelescopeResultsOperator" }) + vim.api.nvim_set_hl(0, "TelescopePersistedDir", { link = "Directory" }) + vim.api.nvim_set_hl(0, "TelescopePersistedBranch", { link = "TelescopeResultsIdentifier" }) telescope_opts = topts end, exports = { diff --git a/lua/telescope/_extensions/persisted/finders.lua b/lua/telescope/_extensions/persisted/finders.lua index fe5f5a2..8934b5d 100644 --- a/lua/telescope/_extensions/persisted/finders.lua +++ b/lua/telescope/_extensions/persisted/finders.lua @@ -1,36 +1,49 @@ +local config = require("persisted.config") local finders = require("telescope.finders") -local entry_display = require("telescope.pickers.entry_display") local M = {} +local no_icons = { + branch = "", + dir = "", + selected = "", +} + M.session_finder = function(sessions) - -- Layout borrowed from: - ---https://github.com/LinArcX/telescope-env.nvim/blob/master/lua/telescope/_extensions/env.lua + local icons = vim.tbl_extend("force", no_icons, config.options.telescope.icons or {}) - local displayer = entry_display.create({ - items = { - { remaining = true }, - }, - }) + local custom_displayer = function(session) + local final_str = "" + local hls = {} - local make_display = function(session) - local str + local function append(str, hl) + local hl_start = #final_str + final_str = final_str .. str + if hl then + table.insert(hls, { { hl_start, #final_str }, hl }) + end + end + + -- is current session + append(session.file_path == vim.v.this_session and (icons.selected .. " ") or " ", "TelescopePersistedIsCurrent") + + -- session path + append(icons.dir, "TelescopePersistedDir") + append(session.dir_path) + + -- branch if session.branch then - str = string.format("%s (branch: %s)", session.dir_path, session.branch) - else - str = session.dir_path + append(" " .. icons.branch .. session.branch, "TelescopePersistedBranch") end - if session.file_path == vim.v.this_session then - str = "* " .. str - end - return displayer({ str }) + + return final_str, hls end return finders.new_table({ results = sessions, entry_maker = function(session) session.ordinal = session.name - session.display = make_display + session.display = custom_displayer session.name = session.name session.branch = session.branch session.file_path = session.file_path