114 lines
2 KiB
Lua
114 lines
2 KiB
Lua
local dashboard = require("alpha.themes.dashboard")
|
|
|
|
--
|
|
-- header
|
|
--
|
|
|
|
local function section_fortune_lines()
|
|
local fortune = vim.api.nvim_exec("silent !fortune", true)
|
|
|
|
local tbl = {}
|
|
local first = true
|
|
for line in fortune:gmatch("[^\r\n]+") do
|
|
if first then
|
|
first = false
|
|
else
|
|
local entry = {
|
|
type = "text",
|
|
val = line,
|
|
opts = { hl = "Number", position = "center" }
|
|
}
|
|
table.insert(tbl, entry)
|
|
end
|
|
end
|
|
|
|
return { type = "group", val = tbl }
|
|
end
|
|
|
|
|
|
|
|
local section_fortune = {
|
|
type = "group",
|
|
val = {
|
|
section_fortune_lines()
|
|
}
|
|
}
|
|
|
|
|
|
--
|
|
-- sessions
|
|
--
|
|
|
|
local function section_sessions_entries()
|
|
local session = require("session")
|
|
|
|
local tbl = {}
|
|
|
|
local s = session.list_sessions()
|
|
local i = 1
|
|
for _, v in pairs(s) do
|
|
local item = v[1]
|
|
local item_short = item:gsub(vim.env.HOME, "~")
|
|
local item_escaped = item:gsub("([\\ $%%])", "\\%1")
|
|
local cmd = "<cmd>SessionLoad " .. item_escaped .. "<CR>"
|
|
table.insert(tbl, dashboard.button("s " .. i, item_short, cmd))
|
|
i = i + 1
|
|
if i > 9 then break end
|
|
end
|
|
|
|
return {
|
|
type = "group",
|
|
val = tbl,
|
|
opts = {},
|
|
}
|
|
end
|
|
|
|
local section_sessions = {
|
|
type = "group",
|
|
val = {
|
|
{ type = "text", val = "Recent sessions", opts = { hl = "String", position = "center" } },
|
|
{ type = "padding", val = 1 },
|
|
section_sessions_entries(),
|
|
},
|
|
}
|
|
|
|
--
|
|
-- actions
|
|
--
|
|
|
|
local section_buttons = {
|
|
type = "group",
|
|
val = {
|
|
{ type = "text", val = "Actions", opts = { hl = "String", position = "center" } },
|
|
{ type = "padding", val = 1 },
|
|
dashboard.button("n", "New file", "<cmd>ene<CR>"),
|
|
dashboard.button("q", "Quit", "<cmd>qa<CR>"),
|
|
},
|
|
position = "center",
|
|
}
|
|
|
|
--
|
|
-- config
|
|
--
|
|
|
|
return {
|
|
layout = {
|
|
{ type = "padding", val = 4 },
|
|
section_fortune,
|
|
{ type = "padding", val = 2 },
|
|
section_sessions,
|
|
{ type = "padding", val = 2 },
|
|
section_buttons,
|
|
},
|
|
opts = {
|
|
margin = 5,
|
|
setup = function()
|
|
vim.api.nvim_create_autocmd('DirChanged', {
|
|
pattern = '*',
|
|
group = "alpha_temp",
|
|
callback = function () require('alpha').redraw() end,
|
|
})
|
|
end,
|
|
},
|
|
}
|