feat: url open handlers

This commit is contained in:
Folke Lemaitre 2022-11-23 16:12:12 +01:00
parent a11fc5a0e0
commit 6f835ab87b
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 24 additions and 0 deletions

View File

@ -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)