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

feat: Make it toggle to the last used repo on nvim open #11

Open
InfiniteRain opened this issue Mar 7, 2024 · 2 comments
Open

feat: Make it toggle to the last used repo on nvim open #11

InfiniteRain opened this issue Mar 7, 2024 · 2 comments

Comments

@InfiniteRain
Copy link

Is there a way to make it open in the last repo use on opening nvim? Currently it defaults to root when I open nvim. If there's no way to change that then I can offer to implement it myself and make a PR.

@imNel imNel changed the title Make it toggle to the last used repo on nvim open feat: Make it toggle to the last used repo on nvim open Mar 10, 2024
@imNel
Copy link
Owner

imNel commented Mar 10, 2024

Hey! Unfortunately this doesn't exist yet but I'm open to PRs :)

@jelleklaver
Copy link

jelleklaver commented Sep 11, 2024

You can make this work with vim-prosession. This automatically tracks starts and opens your sessions.

However, this doesn't work out of the box. The SessionLoadPost autocmd will set the monorepo to the subfolder/subproject you're opening.

For me the following works. I've modified the change_monorepo method so that when it is called with a directory, it will find the git repository ancestor. This will probably not a one-size-fits-all solution, but it might help :-) This will also make sure when you open vim in one of the subproject folders, you will still get the proper monorepo.

I think it would be nice to have this mono_dir function configurable, just like with lspconfig.root_dir.

-- Modify change_monorepo so that it will always pick a git directory.
M.change_monorepo = function(path)
    local git_repo = vim.fn.finddir(".git/..", vim.fn.fnamemodify(path, ":p:h") .. ";")
    M.currentMonorepo = git_repo
    utils.load()
end

I've overridden the method like so, using Lazy as package manager (warning, hacky solution ;-)):

return {
  {
        "imNel/monorepo.nvim",
        config = function()
            local monorepo = require("monorepo")
            local utils = require("monorepo.utils")
            -- Modify change_monorepo so that it will always pick a git directory.
            monorepo.change_monorepo = function(path)
                local git_repo = vim.fn.finddir(".git/..", vim.fn.fnamemodify(path, ":p:h") .. ";")
                monorepo.currentMonorepo = git_repo
                utils.load()
            end
            monorepo.setup()
        end,
        -- Required to allow the change_monorepo method to be overwritten in time.
        lazy = false,
        dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"},
        keys = {
            { "<leader>m", function() require("telescope").extensions.monorepo.monorepo() end },
            { "<leader>n", function() require("monorepo").toggle_project() end },
        },
    }, {
        -- Open previous session
        "dhruvasagar/vim-prosession",
        lazy = false,
        dependencies = {
            "tpope/vim-obsession",
        }
    }
}

Hope this helps!

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

3 participants