Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to integrate with alpha.nvim? #22

Closed
fjchen7 opened this issue Jan 28, 2023 · 3 comments
Closed

How to integrate with alpha.nvim? #22

fjchen7 opened this issue Jan 28, 2023 · 3 comments

Comments

@fjchen7
Copy link

fjchen7 commented Jan 28, 2023

Follow the this guide in README.md I fail to integrate with alpha. I am trying to show all my saved sessions in alpha page. Is there an example? Very thanks!

@jedrzejboczar
Copy link
Owner

jedrzejboczar commented Feb 1, 2023

Hi, I think alpha-nvim is more like a library for building startup screens, as it is actually quite challenging to build something with it (if not using one of the provided themes). That's why I didn't initially include a full example - it's quite user-specific.

But for a starting point you can try the following gist: https://gist.github.com/jedrzejboczar/618b531d1e0de6a956c66132287689aa. It uses some helpers copied from existing alpha-nvim themes and from my config. It creates a startup screen with your sessions, you can change the workspace definitions to suite your needs. You may also experiment with the layout, add some additional highlights in the create_button function, etc.

@fjchen7
Copy link
Author

fjchen7 commented Feb 2, 2023

Thank you for response. I post my version here which may look more concise.

return {  -- lazy.nvim
  "goolord/alpha-nvim",
  event = "VimEnter",
  opts = function()
    local dashboard = require("alpha.themes.dashboard")
    dashboard.section.buttons.val = {
      dashboard.button("f", "" .. " Find Files", ":Telescope find_files<cr>"),
      dashboard.button("e", "" .. " New Files", ":ene <BAR> startinsert <CR>"),
      dashboard.button("o", "" .. " Recent Files", ":Telescope frecency <CR>"),
      dashboard.button("g", "" .. " Find Text", ":Telescope live_grep <CR>"),
      dashboard.button("c", "" .. " Nvim Config", [[<cmd>PossessionLoad config<CR>]]),
      dashboard.button("z", "" .. " Lazy", ":Lazy<CR>"),
      dashboard.button("q", "" .. " Quit", ":qa<CR>"),
      (function()
        local group = { type = "group", opts = { spacing = 0 } }
        group.val = {
          {
            type = "text",
            val = "Sessions",
            opts = {
              position = "center"
            }
          }
        }
        local path = vim.fn.stdpath("data") .. "/possession"
        local files = vim.split(vim.fn.glob(path .. "/*.json"), "\n")
        for i, file in pairs(files) do
          local basename = vim.fs.basename(file):gsub("%.json", "")
          local button = dashboard.button(tostring(i), "" .. basename, "<cmd>PossessionLoad " .. basename .. "<cr>")
          table.insert(group.val, button)
        end
        return group
      end)()
    }
    dashboard.opts.layout[1].val = 8
    return dashboard
  end,
  config = function(_, dashboard)
    require("alpha").setup(dashboard.opts)
  end,
}

image

@jedrzejboczar
Copy link
Owner

Thanks, your example is definitely more concise. I added a link to your example in the README.

You could also try using require('possession.query').as_list() instead of manually globbing the JSON files - this will automatically respect your session_dir settings if you decide to change it in setup and will return a list with session objects so you can use e.g. the .name key. But of course your solution is ok and I don't plan any breaking changes regarding how/where the sessions are stored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants