alpha-nvim icon indicating copy to clipboard operation
alpha-nvim copied to clipboard

Dynamic numbers

Open sarmong opened this issue 3 years ago • 3 comments

I want to change a layout of elements in my config, so I did the following:

local alpha = require("alpha")
local startify_config = require("alpha.themes.startify")

local config = {
  layout = {
    { type = "padding", val = 1 },
    startify_config.section.header,
    { type = "padding", val = 2 },
    startify_config.section.top_buttons,
    startify_config.section.mru_cwd,
    startify_config.section.mru,
    { type = "padding", val = 1 },
    startify_config.section.bottom_buttons,
    startify_config.section.footer,
  },
  opts = {
    margin = 3,
    redraw_on_resize = false,
    setup = function()
      vim.cmd([[
            autocmd alpha_temp DirChanged * lua require('alpha').redraw()
            ]])
    end,
  },
}

alpha.setup(config)

I swapped mru_cwd and mru, because usually the files relevant for the current directory are more important. (Maybe it could be the default?)

However, the numbers didn't change, so I get 10, 1, 2, 3...

  1. Is there an easy way to do this on my side not to rewriting half the config?
  2. If not, how can I do this the hard way?
  3. Can dynamic numbering be added to the plugin?
  4. Maybe ordering mru_cwd before mru would make sense for a lot of people, so it could be made a default?

PS. Thanks for a nice plugin!

sarmong avatar Apr 01 '22 09:04 sarmong

alpha's ui is just data, so you can just mutate the mru_cwd table to a copy of what exists in the code, but with the numbers starting on the right index

    mru_cwd = {
        type = "group",
        val = {
            { type = "padding", val = 1 },
            { type = "text", val = mru_title, opts = { hl = "SpecialComment", shrink_margin = false } },
            { type = "padding", val = 1 },
            {
                type = "group",
                val = function()
                    local x = mru(0, vim.fn.getcwd()) -- the first argument is the beginning index
                    return {x}
                end,
                opts = { shrink_margin = false },
            },
        },
    },

but, this is a little too involved, so i think i'm going to try to make the buttons independent of the order of the mru sections

goolord avatar Apr 01 '22 17:04 goolord

ok, it should behave the way you expect as of https://github.com/goolord/alpha-nvim/commit/c4a3b23ea11ce0f68482bc0c2bccc72e990e4892

goolord avatar Apr 01 '22 18:04 goolord

nvm, this caused some nasty bug. i'll investigate later https://github.com/goolord/alpha-nvim/commit/534a86b348b741ada5bb0d4b83c2c3da6763352a

goolord avatar Apr 02 '22 01:04 goolord