Skip to content

Commit

Permalink
feat: url open handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 23, 2022
1 parent a11fc5a commit 6f835ab
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ function M.file_exists(file)
return vim.loop.fs_stat(file) ~= nil
end

function M.open(uri)
if M.file_exists(uri) then
return vim.cmd.view(uri)
end
local cmd
if vim.fn.has("win32") == 1 then
cmd = { "cmd.exe", "/c", "start", '""', vim.fn.shellescape(uri) }
elseif vim.fn.has("macunix") == 1 then
cmd = { "open", uri }
else
cmd = { "xdg-open", uri }
end

local ret = vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
local msg = {
"Failed to open uri",
ret,
vim.inspect(cmd),
}
vim.notify(table.concat(msg, "\n"), vim.log.levels.ERROR)
end
end

---@param ms number
---@param fn fun()
function M.throttle(ms, fn)
Expand Down

0 comments on commit 6f835ab

Please sign in to comment.