refactor(nvim): better integration of alpha w/ lazy

This commit is contained in:
Price Hiller 2022-12-21 00:31:08 -06:00
parent 130b15ede6
commit fde19bd14c

View File

@ -1,77 +1,80 @@
local alpha = require('alpha')
local startify = require('alpha.themes.startify')
local dashboard = require('alpha.themes.dashboard')
local alpha = require("alpha")
local startify = require("alpha.themes.startify")
local dashboard = require("alpha.themes.dashboard")
-- Set header
local header = {
type = 'text',
type = "text",
val = {
' ',
' ',
' ',
' ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ',
' ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ',
' ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ',
' ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ',
' ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ',
' ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ',
' ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ',
' ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ',
' ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ',
' ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ',
' ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ',
' ',
},
opts = {
position = 'center',
hl = 'Function',
" ",
" ",
" ",
" ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ",
" ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ",
" ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ",
" ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ",
" ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ",
" ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ",
" ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ",
" ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ",
" ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ",
" ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ",
" ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ",
" ",
},
opts = { position = "center", hl = "Delimiter" },
}
-- Subheader, plugin count
local get_plugin_info = function()
local plugins_loaded = {
type = "text",
val = {
(function()
local lazy_stats = require("lazy").stats()
local plugin_count = lazy_stats.count
local loaded_plugins = lazy_stats.loaded
return "" .. loaded_plugins .. "/" .. plugin_count .. " plugins  loaded!"
end)(),
},
opts = { hl = "@conditional", position = "center" },
}
local plugin_info = {
type = "text",
val = {
(function()
if require("lazy.status").has_updates() then
return "Plugin updates available, check :Lazy"
else
return "All plugins up to date"
end
end
local plugin_info = {
type = 'text',
val = {
get_plugin_info()
},
opts = {
hl = 'Comment',
position = 'center',
end)(),
},
opts = { hl = "@decorator", position = "center" },
}
-- Menu
local button = function(sc, txt, keybind)
local sc_ = sc:gsub('%s', ''):gsub('SPC', '<leader>')
local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")
local opts = {
position = 'center',
position = "center",
text = txt,
shortcut = sc,
cursor = 4,
width = 30,
align_shortcut = 'right',
hl_shortcut = 'Number',
hl = 'Function',
align_shortcut = "right",
hl_shortcut = "Number",
hl = "Function",
}
if keybind then
opts.keymap = { 'n', sc_, keybind, { noremap = true, silent = true } }
opts.keymap = { "n", sc_, keybind, { noremap = true, silent = true } }
end
return {
type = 'button',
type = "button",
val = txt,
on_press = function()
local key = vim.api.nvim_replace_termcodes(sc_, true, false, true)
vim.api.nvim_feedkeys(key, 'normal', false)
vim.api.nvim_feedkeys(key, "normal", false)
end,
opts = opts,
}
@ -79,53 +82,48 @@ end
-- Set menu
local buttons = {
type = 'group',
type = "group",
val = {
button('e', ' New File', ':ene <BAR> startinsert <CR>'),
button('f', ' Find File', ':Telescope find_files<CR>'),
button('r', ' Recent', ':Telescope oldfiles<CR>'),
button('s', ' Settings', ':e ~/.config/nvim/<CR>'),
button('u', ' Update Plugins', ':Lazy sync<CR>'),
button('q', ' Quit', ':qa<CR>'),
},
opts = {
spacing = 0,
button("e", " New File", ":ene <BAR> startinsert <CR>"),
button("f", " Find File", ":Telescope find_files<CR>"),
button("r", " Recent", ":Telescope oldfiles<CR>"),
button("s", " Settings", ":e ~/.config/nvim/<CR>"),
button("u", " Update Plugins", ":Lazy sync<CR>"),
button("q", " Quit", ":qa<CR>"),
},
opts = { spacing = 0 },
}
-- Footer 2, fortune
local fortune = {
type = 'text',
val = require('alpha.fortune')(),
opts = {
position = 'center',
hl = 'Comment',
},
type = "text",
val = require("alpha.fortune")(),
opts = { position = "center", hl = "Comment" },
}
local padding = function()
return { type = 'padding', val = 4 }
local padding = function(pad_amount)
return { type = "padding", val = pad_amount }
end
local opts = {
layout = {
padding(),
padding(12),
header,
padding(),
padding(4),
plugin_info,
padding(),
padding(1),
plugins_loaded,
padding(4),
buttons,
padding(),
padding(4),
fortune,
},
opts = {
margin = 5,
},
opts = { margin = 5 },
}
-- Send config to alpha
alpha.setup(opts)
vim.api.nvim_create_autocmd('FileType', {
pattern = 'alpha',
vim.api.nvim_create_autocmd("FileType", {
pattern = "alpha",
callback = function()
vim.opt_local.cursorline = false
end,