mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
fix(gitbrowse): opts.notify
This commit is contained in:
parent
6b98aa11d3
commit
243655796e
1 changed files with 9 additions and 3 deletions
|
@ -11,6 +11,7 @@ local uv = vim.uv or vim.loop
|
||||||
---@class snacks.gitbrowse.Config
|
---@class snacks.gitbrowse.Config
|
||||||
---@field url_patterns? table<string, table<string, string|fun(fields:snacks.gitbrowse.Fields):string>>
|
---@field url_patterns? table<string, table<string, string|fun(fields:snacks.gitbrowse.Fields):string>>
|
||||||
local defaults = {
|
local defaults = {
|
||||||
|
notify = true, -- show notification on open
|
||||||
-- Handler to open the url in a browser
|
-- Handler to open the url in a browser
|
||||||
---@param url string
|
---@param url string
|
||||||
open = function(url)
|
open = function(url)
|
||||||
|
@ -106,7 +107,7 @@ local function system(cmd, err)
|
||||||
local proc = vim.fn.system(cmd)
|
local proc = vim.fn.system(cmd)
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
Snacks.notify.error({ err, proc }, { title = "Git Browse" })
|
Snacks.notify.error({ err, proc }, { title = "Git Browse" })
|
||||||
error(err)
|
error("__ignore__")
|
||||||
end
|
end
|
||||||
return vim.split(vim.trim(proc), "\n")
|
return vim.split(vim.trim(proc), "\n")
|
||||||
end
|
end
|
||||||
|
@ -124,7 +125,10 @@ end
|
||||||
|
|
||||||
---@param opts? snacks.gitbrowse.Config
|
---@param opts? snacks.gitbrowse.Config
|
||||||
function M.open(opts)
|
function M.open(opts)
|
||||||
pcall(M._open, opts) -- errors are handled with notifications
|
local ok, err = pcall(M._open, opts) -- errors are handled with notifications
|
||||||
|
if not ok and err ~= "__ignore__" then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts? snacks.gitbrowse.Config
|
---@param opts? snacks.gitbrowse.Config
|
||||||
|
@ -184,7 +188,9 @@ function M._open(opts)
|
||||||
|
|
||||||
local function open(remote)
|
local function open(remote)
|
||||||
if remote then
|
if remote then
|
||||||
Snacks.notify(("Opening [%s](%s)"):format(remote.name, remote.url), { title = "Git Browse" })
|
if opts.notify then
|
||||||
|
Snacks.notify(("Opening [%s](%s)"):format(remote.name, remote.url), { title = "Git Browse" })
|
||||||
|
end
|
||||||
opts.open(remote.url)
|
opts.open(remote.url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue