From 6f835ab87b5f8ecef630cd9b024fac03795bb674 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 23 Nov 2022 16:12:12 +0100 Subject: [PATCH] feat: url open handlers --- lua/lazy/core/util.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lua/lazy/core/util.lua b/lua/lazy/core/util.lua index 2da728b..a489372 100644 --- a/lua/lazy/core/util.lua +++ b/lua/lazy/core/util.lua @@ -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)