Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: sessions added to startify page #268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions lua/alpha/themes/startify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ end
local nvim_web_devicons = {
enabled = true,
highlight = true,
sessions = false,
}

local function get_extension(fn)
Expand Down Expand Up @@ -158,6 +159,48 @@ local function mru_title()
return "MRU " .. vim.fn.getcwd()
end

local session_manager_exists, sess_man = pcall(require, "session_manager.utils")

local session_buttons = {
type = "group",
val = {}
}

local sessions_group = {
type = "group",
val = {},
}

local num_sessions = 0

if session_manager_exists then
local sessions = sess_man.get_sessions()
local ico
if nvim_web_devicons.sessions then
ico, _ = require("nvim-web-devicons").get_icon("", "cfg", { default = true })
end
for i,v in ipairs(sessions) do
local filename = v.dir.filename
if nvim_web_devicons.sessions then
filename = ico .. " " .. filename
end
table.insert(session_buttons.val, button(
tostring(i - 1),
filename,
-- ico .. " " .. v.dir.filename,
[[<cmd>lua require"session_manager.utils".load_session("]]
.. v.filename .. [[", true)<CR>]]
))
end
num_sessions = #sessions
if num_sessions > 0 then
table.insert(sessions_group.val, { type = "padding", val = 1 })
table.insert(sessions_group.val, { type = "text", val = "Sessions", opts = { hl = "SpecialComment" } })
table.insert(sessions_group.val, { type = "padding", val = 1 })
table.insert(sessions_group.val, session_buttons)
end
end

local section = {
header = default_header,
top_buttons = {
Expand All @@ -166,6 +209,7 @@ local section = {
button("e", "New file", "<cmd>ene <CR>"),
},
},
sessions = sessions_group,
-- note about MRU: currently this is a function,
-- since that means we can get a fresh mru
-- whenever there is a DirChanged. this is *really*
Expand All @@ -182,7 +226,7 @@ local section = {
{
type = "group",
val = function()
return { mru(10) }
return { mru(10 + num_sessions) }
end,
},
},
Expand All @@ -196,7 +240,7 @@ local section = {
{
type = "group",
val = function()
return { mru(0, vim.fn.getcwd()) }
return { mru(0 + num_sessions, vim.fn.getcwd()) }
end,
opts = { shrink_margin = false },
},
Expand All @@ -220,6 +264,7 @@ local config = {
section.header,
{ type = "padding", val = 2 },
section.top_buttons,
section.sessions,
section.mru_cwd,
section.mru,
{ type = "padding", val = 1 },
Expand Down Expand Up @@ -256,3 +301,4 @@ return {
-- deprecated
opts = config,
}