Skip to content

Conversation

@casedami
Copy link
Contributor

@casedami casedami commented Oct 8, 2024

Added a simple function to check if a session for the cwd exists. My use case for it is to conditionally show an option on my startup dashboard to load the session for the cwd.

For example:

local get_actions = function()
  local actions = {
    { action = "Telescope find_files", desc = " find file", icon = "", key = "f", },
    { action = "Telescope oldfiles cwd_only=true", desc = " recent files", icon = "", key = "r", },
    { action = "Oil", desc = " explorer", icon = "󱏒 ", key = "e", },
    { action = "Telescope live_grep", desc = " grep", icon = "", key = "g", },
    { action = "Lazy", desc = " lazy", icon = "󰒲 ", key = "l", },
    { action = function() vim.api.nvim_input("<cmd>qa<cr>") end, desc = " quit", icon = "", key = "q", },
  }

  if require("session_manager").current_dir_session_exists() then
    table.insert(actions, 5, {
      action = "SessionManager load_current_dir_session",
      desc = " restore session",
      icon = "",
      key = "s",
    })
  end

  if require("cmill.core.util").is_git_repo() then
    table.insert(
      actions,
      5,
      { action = "Neogit", desc = " git", icon = "", key = "G" }
    )
  end
  return actions
end

return {
  {
    "nvimdev/dashboard-nvim",
    -- snip --
        config = {
          center = get_actions(),
    -- snip --

@Shatur
Copy link
Owner

Shatur commented Oct 8, 2024

Thanks!

@Shatur Shatur merged commit ce43f2e into Shatur:master Oct 8, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants