Skip to content

Commit

Permalink
Refresh telescope picker after deleting a session file
Browse files Browse the repository at this point in the history
  • Loading branch information
sebajun9 committed Aug 14, 2024
1 parent 220ec71 commit d40473f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lua/seshi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function M.defaults()
save_dir = vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/'),
autoload = true,
use_git_root = true,
silent = false,
silent = true,
telescope = {
mappings = {
delete_session = '<C-d>',
Expand Down
76 changes: 41 additions & 35 deletions lua/telescope/_extensions/seshi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,53 @@ local action_state = require('telescope.actions.state')
local seshi = require('seshi')
local utils = require('seshi.utils')

local function list_sessions()
local sessions = {}
local save_dir = seshi.options.save_dir
local files = vim.fn.glob(save_dir .. '*', false, true)
local function search_sessions(opts)
opts = opts or {}

for _, file in ipairs(files) do
local session_name = vim.fn.fnamemodify(file, ':t')
local dir_path, branch = utils.split_session_filename(session_name)
-- Decode the path and branch
dir_path = utils.decode_path(dir_path)
branch = branch and utils.decode_path(branch) or nil
local function list_sessions()
local sessions = {}
local save_dir = seshi.options.save_dir
local files = vim.fn.glob(save_dir .. '*', false, true)

table.insert(sessions, {
name = session_name,
file_path = file,
dir_path = dir_path,
branch = branch,
})
end
for _, file in ipairs(files) do
local session_name = vim.fn.fnamemodify(file, ':t')
local dir_path, branch = utils.split_session_filename(session_name)
-- Decode the path and branch
dir_path = utils.decode_path(dir_path)
branch = branch and utils.decode_path(branch) or nil

return sessions
end
table.insert(sessions, {
name = session_name,
file_path = file,
dir_path = dir_path,
branch = branch,
})
end

local function search_sessions(opts)
opts = opts or {}
return sessions
end

local function make_finder()
return finders.new_table({
results = list_sessions(),
entry_maker = function(entry)
local display = entry.dir_path
if entry.branch then
display = display .. ' (' .. entry.branch .. ')'
end
return {
value = entry,
display = display,
ordinal = entry.name,
}
end,
})
end

pickers
.new(opts, {
prompt_title = 'Sessions',
finder = finders.new_table({
results = list_sessions(),
entry_maker = function(entry)
local display = entry.dir_path
if entry.branch then
display = display .. ' (' .. entry.branch .. ')'
end
return {
value = entry,
display = display,
ordinal = entry.name,
}
end,
}),
finder = make_finder(),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
Expand All @@ -63,6 +67,8 @@ local function search_sessions(opts)
if selection then
local file_path = selection.value.file_path
seshi.delete_session(file_path)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:refresh(make_finder(), { reset_prompt = false })
end
end)
return true
Expand Down

0 comments on commit d40473f

Please sign in to comment.