diff --git a/lua/telescope/_extensions/packer.lua b/lua/telescope/_extensions/packer.lua index 436a5f8..0b114e9 100644 --- a/lua/telescope/_extensions/packer.lua +++ b/lua/telescope/_extensions/packer.lua @@ -30,6 +30,30 @@ local setup = function(opts) end end +local function opener() + local sysname = vim.loop.os_uname().sysname + if sysname == "Darwin" then + return 'open' + elseif sysname == "Windows" then + return "explorer" + elseif vim.fn.executable("wslview") then + return 'wslview' + elseif vim.fn.executable("xdg-open") then + return 'xdg-open' + else + return nil + end +end + +local function get_url(path) + local url = vim.fn.trim(vim.fn.system(string.format("git -C %s ls-remote --get-url", path))) + if string.sub(url, 1, 6) == 'ssh://' then + url, _ = string.gsub(url, '^ssh://%w+@', 'https://') + url, _ = string.gsub(url, '^ssh://', 'https://') + end + return url +end + local plugins = function(opts) opts = vim.tbl_deep_extend("force", user_opts, opts or {}) @@ -89,8 +113,12 @@ local plugins = function(opts) local selection = action_state.get_selected_entry() actions._close(prompt_bufnr) - local cmd = vim.fn.has "win32" == 1 and "explorer" or vim.fn.has "mac" == 1 and "open" or "xdg-open" - local url = vim.fn.trim(vim.fn.system(string.format("git -C %s ls-remote --get-url", selection.path))) + local cmd = opener() + if cmd == nil then + vim.notify("No executables to open file/url", vim.log.levels.ERROR) + return + end + local url = get_url(selection.path) Job:new({command = cmd, args = {url}}):start() end