mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
feat(git): added leader-gB to browse remotes of the current repo
This commit is contained in:
parent
86811ad7aa
commit
c4ccd7cbce
2 changed files with 33 additions and 0 deletions
|
@ -134,6 +134,7 @@ map("n", "<leader>ub", function() LazyVim.toggle("background", false, {"light",
|
||||||
map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
|
map("n", "<leader>gg", function() LazyVim.lazygit( { cwd = LazyVim.root.git() }) end, { desc = "Lazygit (Root Dir)" })
|
||||||
map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
|
map("n", "<leader>gG", function() LazyVim.lazygit() end, { desc = "Lazygit (cwd)" })
|
||||||
map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" })
|
map("n", "<leader>gb", LazyVim.lazygit.blame_line, { desc = "Git Blame Line" })
|
||||||
|
map("n", "<leader>gB", LazyVim.lazygit.browse, { desc = "Git Browse" })
|
||||||
|
|
||||||
map("n", "<leader>gf", function()
|
map("n", "<leader>gf", function()
|
||||||
local git_path = vim.api.nvim_buf_get_name(0)
|
local git_path = vim.api.nvim_buf_get_name(0)
|
||||||
|
|
|
@ -159,4 +159,36 @@ function M.blame_line(opts)
|
||||||
return require("lazy.util").float_cmd(cmd, opts)
|
return require("lazy.util").float_cmd(cmd, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.browse()
|
||||||
|
local config = require("lazy.manage.git").get_config(LazyVim.root.detectors.pattern(0, { ".git" })[1])
|
||||||
|
local remotes = {} ---@type {name:string, url:string}[]
|
||||||
|
for name, url in pairs(config) do
|
||||||
|
name = name:match("^remote%.(.-)%.url$")
|
||||||
|
if name then
|
||||||
|
url = url:gsub("git@github.com:", "https://github.com/"):gsub("%.git$", "") --[[@as string]]
|
||||||
|
table.insert(remotes, { name = name, url = url })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function open(remote)
|
||||||
|
if remote then
|
||||||
|
LazyVim.info(("Opening [%s](%s)"):format(remote.name, remote.url))
|
||||||
|
vim.ui.open(remote.url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #remotes == 0 then
|
||||||
|
return LazyVim.error("No git remotes found")
|
||||||
|
elseif #remotes == 1 then
|
||||||
|
return open(remotes[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.ui.select(remotes, {
|
||||||
|
prompt = "Select remote to browse",
|
||||||
|
format_item = function(item)
|
||||||
|
return item.name .. (" "):rep(8 - #item.name) .. " 🔗 " .. item.url
|
||||||
|
end,
|
||||||
|
}, open)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue