From 0ddc2b874d9fb04474be7323d695847e5235e158 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 27 May 2022 13:03:52 +0200 Subject: vim: update alpha config --- .vim/lua/plugins.lua | 170 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 125 insertions(+), 45 deletions(-) (limited to '.vim/lua') diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index c8f013c..3f109fe 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -978,15 +978,32 @@ return require('packer').startup({function() use {'goolord/alpha-nvim', -- {{{ config = function() local alpha = require('alpha') - local them = require('alpha.themes.startify') - local hr = function() - local margin = 3; return string.rep(' ', margin) .. string.rep('─', vim.o.columns-(2*margin)) - end - them.opts.layout = { - {type = 'padding', val = 1}, - them.section.header, - {type = 'padding', val = 1}, - { + local them = require('alpha.themes.theta') + local MAX_WIDTH = 80 + local header = require('alpha.themes.dashboard').section.header + local button = function(...) + local b = require('alpha.themes.dashboard').button(...) + b.opts = vim.tbl_extend('force', b.opts, { + hl = 'Normal', + width = MAX_WIDTH, + }) + return b + end + local pad = function(str, max_width) + return str .. string.rep(' ', ((max_width or vim.opt.columns:get()) - vim.fn.strdisplaywidth(str))) + end + local hr = function(margin, max_width) -- {{{ + return { + type = 'text', + val = string.rep(' ', margin) .. string.rep('─', max_width - (2*margin)), + opts = { + position = 'center', + hl = 'Comment', + } + } + end -- }}} + local fortune = function(margin, max_width) -- {{{ + return { type = 'text', val = function() local j = require('plenary.job'):new({ @@ -998,64 +1015,127 @@ return require('packer').startup({function() local new = {} for i = 1, #lines do if not (vim.trim(lines[i]) == '') then - new[#new+1] = string.rep(' ', 3) .. lines[i] + local line = string.rep(' ', margin) .. lines[i] + new[#new+1] = line end end return new + -- return require('alpha.fortune')(max_width) end, opts = { + position = 'center', hl = 'AlphaFortune', + }, + } + end -- }}} + local here = function(max_width) -- {{{ + return { + type = 'text', + val = function() return pad('❱ ' .. vim.loop.cwd(), max_width) end, + opts = { + position = 'center', + hl = 'Title', } - }, - {type = 'padding', val = 1}, - {type = 'text', val = hr, opts = {hl = 'Comment'}}, - {type = 'padding', val = 1}, - { - type = 'group', - val = { - them.button('e', '󰈔 new', [[ene startinsert]]), - them.button('r', '󰈸 live grep', [[lua require('misc').live_grep()]]), - them.button('f', '󰝰 find files', [[lua require('misc').find_files()]]), - them.button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), - them.button('o', '󰃶 orgmode', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')]]), - them.button('u', '󰚰 update plugins', [[lua require('packer').sync()]]), - them.button('c', '󰂓 edit config', [[lua require('telescope.builtin').find_files({search_dirs={vim.env.HOME..'/.vim/'}})]]), - them.button('M', '󰇮 mail', [[Himalaya]]), - } - }, - {type = 'padding', val = 1}, - {type = 'text', val = function() return ' ❱ ' .. vim.loop.cwd() end, opts = {hl = 'Title'}}, - {type = 'padding', val = 1}, - { + } + end -- }}} + local mru = function(max_width) -- {{{ + return { type = 'group', val = function() local cwd = vim.loop.cwd() local oldfiles = {} for _, v in pairs(vim.v.oldfiles) do if #oldfiles == 10 then break end - if vim.startswith(v, cwd) then - oldfiles[#oldfiles+1] = v + if vim.startswith(v, cwd) and (vim.fn.filereadable(v) == 1) then + table.insert(oldfiles, v) end end - local val = {} + if not oldfiles or #oldfiles == 0 then return {} end + local items = {} + table.insert(items, { + type = 'text', + val = pad('MRU:', max_width), + opts = { position = 'center', hl = 'Comment' } + }) for i, fn in pairs(oldfiles) do local shortfn = vim.fn.fnamemodify(fn, ':.') - val[#val+1] = them.button(tostring(i-1), shortfn, ":e " .. fn .. " ") + if vim.fn.strdisplaywidth(shortfn) > max_width then + shortfn = require('plenary.path').new(shortfn):shorten(1, {-2, -1}) + end + if vim.fn.strdisplaywidth(shortfn) > max_width then + local over = vim.fn.strdisplaywidth(shortfn) - max_width + over = over + 4 + shortfn = '_ ' .. shortfn:sub(over+1, -1) + end + table.insert(items, button(tostring(i-1), shortfn, ":e " .. fn .. " ")) end - return val + return items end, - }, + opts = { + position = 'center', + }, + } + end -- }}} + local buffers = function(max_width) -- {{{ + return { + type = 'group', + val = function() + local items = {} + local bufnrs = vim.tbl_filter(function(bufnr) + if 1 ~= vim.fn.buflisted(bufnr) then + return false + end + return true + end, vim.api.nvim_list_bufs()) + table.sort(bufnrs, function(a, b) + return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused + end) + if not bufnrs or #bufnrs == 0 then return {} end + -- add padding and hr + table.insert(items, {type = 'padding', val = 1}) + table.insert(items, hr(0, MAX_WIDTH)) + table.insert(items, { + type = 'text', + val = pad('Buffers:', max_width), + opts = { position = 'center', hl = 'Comment' } + }) + for _, bufnr in ipairs(bufnrs) do + local bufpath = require('plenary.path').new(vim.fn.getbufinfo(bufnr)[1].name):shorten(1, {-2, -1}) + table.insert(items, button('b'..bufnr, bufpath, ':b'..bufnr..'')) + end + return items + end, + opts = { + position = 'center', + }, + } + end -- }}} + them.config.layout = { + {type = 'padding', val = 2}, + header, + {type = 'padding', val = 1}, + fortune(0, MAX_WIDTH), + {type = 'padding', val = 1}, + hr(0, MAX_WIDTH), + {type = 'padding', val = 1}, + {type = 'group', val = { + button('e', '󰈔 new', [[ene startinsert]]), + button('r', '󰈸 live grep', [[lua require('misc').live_grep()]]), + button('f', '󰝰 find files', [[lua require('misc').find_files()]]), + button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), + -- button('o', '󰃶 orgmode', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')]]), + button('T', '󰃶 todos', [[lua require('telescope._extensions.todo-comments').exports.todo {cwd=vim.env.ZK_NOTEBOOK_DIR}]]), + button('u', '󰚰 update plugins', [[lua require('packer').sync()]]), + button('v', '󰂓 edit config', [[lua require('telescope.builtin').find_files {search_dirs={vim.env.HOME..'/.vim/'}}]]), + button('M', '󰇮 mail', [[Himalaya]]), + }}, {type = 'padding', val = 1}, - {type = 'text', val = hr, opts = {hl = 'Comment'}}, + here(MAX_WIDTH), {type = 'padding', val = 1}, - -- { - -- type = 'group', - -- val = { - -- them.button('q', 'quit', [[:quit]]), - -- }, - -- }, + mru(MAX_WIDTH), + buffers(MAX_WIDTH), } - alpha.setup(them.opts) + alpha.setup(them.config) do local group = vim.api.nvim_create_augroup('AlphaIndent', { clear = true }) -- cgit 1.4.1