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