snacks.nvim icon indicating copy to clipboard operation
snacks.nvim copied to clipboard

feat(picker): Support git browse for a specific commit, directly from git objects like git_log git_log_line git_log_file.

Open rjshrjndrn opened this issue 10 months ago • 6 comments

Description

Right now there is not way to directly open a commit in browser from git log apart from checking out locally. from any commit press gb in normal mode to open the commit in web.

Screenshots

image image

I'm using LazyVim and I've added the keybinding config in my plugin config. I think it'd be good if we can add as the default keybinding

return {
  "rjshrjndrn/snacks.nvim",
  opts = function(_, opts)
    local preview_window_opts = {
      input = {
        keys = {
          ["gb"] = {
            "git_browse",
            mode = { "n" },
          },
        },
      },
    }
    local gitbrowse = require("snacks.gitbrowse")
    return vim.tbl_deep_extend("force", opts or {}, {
      picker = {
        sources = {
          git_log = {
            win = preview_window_opts,
          },
          git_log_line = {
            win = preview_window_opts,
          },
          git_log_file = {
            win = preview_window_opts,
          },
        },
        actions = {
          git_browse = function(picker, item)
            -- picker:close()
            -- vim.notify(vim.inspect(item), vim.log.levels.INFO)
            gitbrowse.open({ what = "commit", commit = item.commit })
          end,
        },
      },
    })
  end,
}

rjshrjndrn avatar Feb 22 '25 05:02 rjshrjndrn

If you press <M-w> to cycle through to the list window, then if you put your cursor over a commit sha and press <leader>gB it will do what you want.

PS: Oh you mean a separate action to directly operate on the commit itself, that's why you're exposing commit in opts. I misunderstood.

dpetka2001 avatar Feb 22 '25 12:02 dpetka2001

This will also close #393, which I believe is better to expose commit in opts if it's something that the maintainer would consider adding.

dpetka2001 avatar Feb 22 '25 12:02 dpetka2001

HI @folke Can you kindly have a look at the PR and suggest any changes needed.

Thank you.

rjshrjndrn avatar Mar 02 '25 00:03 rjshrjndrn

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Apr 06 '25 02:04 github-actions[bot]

@folke Gentle reminder

rjshrjndrn avatar Apr 12 '25 05:04 rjshrjndrn

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar May 14 '25 02:05 github-actions[bot]