Skip to content

Commit

Permalink
[WIP]: Thu Dec 14 09:48:27 AM EST 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Dec 14, 2023
1 parent d6297ee commit a32f701
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions lua/sg/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,46 @@ end
-- Probably will break on me unexpectedly. Nice
utils.system = vim.system or (require "sg.vendored.vim-system")

utils.open = vim.ui.open
or function(path)
vim.validate {
path = { path, "string" },
}
local is_uri = path:match "%w+:"
if not is_uri then
path = vim.fn.expand(path)
end

local cmd
utils.open = function(...)
local open = vim.ui.open
or function(path)
vim.validate {
path = { path, "string" },
}
local is_uri = path:match "%w+:"
if not is_uri then
path = vim.fn.expand(path)
end

if vim.fn.has "mac" == 1 then
cmd = { "open", path }
elseif vim.fn.has "win32" == 1 then
if vim.fn.executable "rundll32" == 1 then
cmd = { "rundll32", "url.dll,FileProtocolHandler", path }
local cmd

if vim.fn.has "mac" == 1 then
cmd = { "open", path }
elseif vim.fn.has "win32" == 1 then
if vim.fn.executable "rundll32" == 1 then
cmd = { "rundll32", "url.dll,FileProtocolHandler", path }
else
return nil, "vim.ui.open: rundll32 not found"
end
elseif vim.fn.executable "wslview" == 1 then
cmd = { "wslview", path }
elseif vim.fn.executable "xdg-open" == 1 then
cmd = { "xdg-open", path }
else
return nil, "vim.ui.open: rundll32 not found"
return nil, "vim.ui.open: no handler found (tried: wslview, xdg-open)"
end
elseif vim.fn.executable "wslview" == 1 then
cmd = { "wslview", path }
elseif vim.fn.executable "xdg-open" == 1 then
cmd = { "xdg-open", path }
else
return nil, "vim.ui.open: no handler found (tried: wslview, xdg-open)"
end

local rv = utils.system(cmd, { text = true, detach = true }):wait()
if rv.code ~= 0 then
local msg = ("vim.ui.open: command failed (%d): %s"):format(rv.code, vim.inspect(cmd))
return rv, msg
local rv = utils.system(cmd, { text = true, detach = true }):wait()
if rv.code ~= 0 then
local msg = ("vim.ui.open: command failed (%d): %s"):format(rv.code, vim.inspect(cmd))
return rv, msg
end

return rv, nil
end

return rv, nil
end
open(...)
end

-- From https://gist.github.com/jrus/3197011
utils.uuid = function()
Expand Down

0 comments on commit a32f701

Please sign in to comment.