diff options
Diffstat (limited to '.vim/lua')
| -rw-r--r-- | .vim/lua/plugins.lua | 170 |
1 files changed, 125 insertions, 45 deletions
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', [[<cmd>ene <bar> startinsert<cr>]]), - them.button('r', ' live grep', [[<cmd>lua require('misc').live_grep()<cr>]]), - them.button('f', ' find files', [[<cmd>lua require('misc').find_files()<cr>]]), - them.button('m', ' mru', [[<cmd>lua require('telescope.builtin').oldfiles()<cr>]]), - them.button('o', ' orgmode', [[<cmd>lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')<cr>]]), - them.button('u', ' update plugins', [[<cmd>lua require('packer').sync()<cr>]]), - them.button('c', ' edit config', [[<cmd>lua require('telescope.builtin').find_files({search_dirs={vim.env.HOME..'/.vim/'}})<cr>]]), - them.button('M', ' mail', [[<cmd>Himalaya<cr>]]), - } - }, - {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 .. " <cr>") + 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 .. " <cr>")) 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..'<cr>')) + 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', [[<cmd>ene <bar> startinsert<cr>]]), + button('r', ' live grep', [[<cmd>lua require('misc').live_grep()<cr>]]), + button('f', ' find files', [[<cmd>lua require('misc').find_files()<cr>]]), + button('m', ' mru', [[<cmd>lua require('telescope.builtin').oldfiles()<cr>]]), + -- button('o', ' orgmode', [[<cmd>lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')<cr>]]), + button('T', ' todos', [[<cmd>lua require('telescope._extensions.todo-comments').exports.todo {cwd=vim.env.ZK_NOTEBOOK_DIR}<cr>]]), + button('u', ' update plugins', [[<cmd>lua require('packer').sync()<cr>]]), + button('v', ' edit config', [[<cmd>lua require('telescope.builtin').find_files {search_dirs={vim.env.HOME..'/.vim/'}}<cr>]]), + button('M', ' mail', [[<cmd>Himalaya<cr>]]), + }}, {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<cr>]]), - -- }, - -- }, + 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 }) |