-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
tools.open_url
option to allow overriding url handler (#58)
- Loading branch information
Showing
7 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
---@mod rustaceanvim.os Utilities for interacting with the operating system | ||
|
||
local os = {} | ||
|
||
local compat = require('rustaceanvim.compat') | ||
|
||
---@param url string | ||
function os.open_url(url) | ||
---@param obj table | ||
local function on_exit(obj) | ||
if obj.code ~= 0 then | ||
vim.schedule(function() | ||
vim.notify('Could not open URL: ' .. url, vim.log.levels.ERROR) | ||
end) | ||
end | ||
end | ||
|
||
if vim.fn.has('mac') == 1 then | ||
compat.system({ 'open', url }, nil, on_exit) | ||
return | ||
end | ||
if vim.fn.executable('sensible-browser') == 1 then | ||
compat.system({ 'sensible-browser', url }, nil, on_exit) | ||
return | ||
end | ||
if vim.fn.executable('xdg-open') == 1 then | ||
compat.system({ 'xdg-open', url }, nil, on_exit) | ||
return | ||
end | ||
local ok, err = pcall(vim.fn['netrw#BrowseX'], url, 0) | ||
if not ok then | ||
vim.notify('Could not open external docs. Neither xdg-open, nor netrw found: ' .. err, vim.log.levels.ERROR) | ||
end | ||
end | ||
|
||
return os |