Skip to content

Commit 572a3d7

Browse files
committed
include helper function to open url in browser
1 parent c2c5c6c commit 572a3d7

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ In `visual` mode, searches for the selected text.
66

77
### Demo
88

9-
109
https://user-images.githubusercontent.com/33713262/226383032-113b4db8-27a3-4b8f-aa36-c0765b2cc903.mp4
1110

12-
13-
1411
### Install
1512

1613
```lua
@@ -21,18 +18,18 @@ https://user-images.githubusercontent.com/33713262/226383032-113b4db8-27a3-4b8f-
2118
{
2219
"<leader>feg",
2320
function()
24-
local url = require("csgithub").search({
21+
local csgithub = require("csgithub")
22+
23+
local url = csgithub.search({
2524
includeFilename = false,
2625
includeExtension = true,
2726
})
2827

29-
if url then
30-
require("util").open_url(url)
31-
end
28+
csgithub.open(url)
3229
end,
3330
mode = { "n", "v" },
3431
desc = "Search Github",
3532
},
3633
},
37-
},
34+
}
3835
```

lua/csgithub/init.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,20 @@ M.search = function(args)
1717
return url
1818
end
1919

20+
function M.open(url)
21+
-- return if url is empty
22+
if url == nil or url == "" then
23+
print("Error: url is empty!")
24+
return
25+
end
26+
27+
if vim.fn.has("mac") == 1 then
28+
vim.fn.jobstart({ "open", url }, { detach = true })
29+
elseif vim.fn.has("unix") == 1 then
30+
vim.fn.jobstart({ "xdg-open", url }, { detach = true })
31+
else
32+
print("Error: unknown open command on this OS!")
33+
end
34+
end
35+
2036
return M

0 commit comments

Comments
 (0)