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

MRU on Branch #38

Open
guilhermeprokisch opened this issue Oct 8, 2021 · 4 comments
Open

MRU on Branch #38

guilhermeprokisch opened this issue Oct 8, 2021 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@guilhermeprokisch
Copy link

It's possible to alpha-stratify be aware of MRU files in the current branch?

@goolord
Copy link
Owner

goolord commented Oct 8, 2021

does git track this information? i think maybe you could write something that lists files in a directory sorted by their modified by date, which would track with each branch, but then it wouldn't track files which were opened but not modified.

@goolord goolord added help wanted Extra attention is needed good first issue Good for newcomers enhancement New feature or request labels Feb 14, 2023
@marcelarie
Copy link

marcelarie commented Feb 5, 2024

This command all the files that were edited in the last 5 commits.

{ git diff --name-only && git log --pretty=format: --name-only HEAD~5..HEAD; } | sort | uniq

Is there a way to pipe this to alpha ? So it shows the list of files like the MRU ones?

@marcelarie
Copy link

marcelarie commented Feb 5, 2024

I sort of found a way with easypick, telescope and alpha combined:

return {
    "axkirillov/easypick.nvim",
    dependencies = {"nvim-telescope/telescope.nvim"},
    config = function()
        local easypick = require "easypick"

        easypick.setup {
            pickers = {
                -- Show changed files in the last 5 commits
                {
                    name = "changed_files",
                    command = "{ git diff --name-only && git log --pretty=format: --name-only HEAD~5..HEAD; } | sort | uniq",
                    previewer = easypick.previewers.branch_diff {
		        base_branch = "HEAD~5",
		    },
                }
            }
        }
        vim.keymap.set("n", "<leader>cf", "<cmd>Easypick changed_files<CR>")
    end
}

And then in alpha.nvim I have a button like this:

startify.button("cf", "changed files", "<cmd>Easypick changed_files<cr>")

But it would be nice to pipe command, or the results of lua functions, directly to alpha and show the result like the MRU list.

@bezhermoso
Copy link

@marcelarie Adding this action to your snippet makes it work in cases where Neovim's cwd is not Git's root dir (e.g. you primarily work in a sub-directory of a huge monorepo):

action = function(prompt_bufnr, _)
    telescope_actions.select_default:replace(function()
        telescope_actions.close(prompt_bufnr)
        local selection = telescope_action_state.get_selected_entry()
        local git_root_path = require("plenary.job"):new({ command = "git", args = { "rev-parse", "--show-toplevel" } }):sync()[1]
        vim.cmd(string.format("e %s/%s", git_root_path, selection[1]))
    end)
    return true
end,

Thanks for sharing your snippet, I find myself use it often!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants