1
1
local helper = require (" gx.helper" )
2
2
3
- local keymap = vim .keymap .set
4
3
local sysname = vim .loop .os_uname ().sysname
5
4
6
5
local M = {}
7
6
8
- -- search for url with handler
9
- local function search_for_url ()
10
- local line = vim .api .nvim_get_current_line ()
11
- local mode = vim .api .nvim_get_mode ().mode
12
-
13
- -- cut if in visual mode
14
- line = helper .cut_with_visual_mode (mode , line )
15
-
7
+ function M .browse (mode , line )
16
8
-- search for url
17
9
local url =
18
10
require (" gx.handler" ).get_url (mode , line , M .options .handlers , M .options .handler_options )
@@ -21,23 +13,22 @@ local function search_for_url()
21
13
return
22
14
end
23
15
24
- return M .browse (url )
25
- end
26
-
27
- function M .browse (url )
28
16
return require (" gx.shell" ).execute_with_error (
29
17
M .options .open_browser_app ,
30
18
M .options .open_browser_args ,
31
19
url
32
20
)
33
21
end
34
22
35
- -- create keybindings
36
- local function bind_keys ()
37
- vim .g .netrw_nogx = 1 -- disable netrw gx
23
+ -- search for url with handler
24
+ local function open ()
25
+ local line = vim .api .nvim_get_current_line ()
26
+ local mode = vim .api .nvim_get_mode ().mode
38
27
39
- local opts = { noremap = true , silent = true }
40
- keymap ({ " n" , " x" }, " gx" , search_for_url , opts )
28
+ -- cut if in visual mode
29
+ line = helper .cut_with_visual_mode (mode , line )
30
+
31
+ return M .browse (mode , line )
41
32
end
42
33
43
34
-- get the app for opening the webbrowser
@@ -87,12 +78,18 @@ local function with_defaults(options)
87
78
}
88
79
end
89
80
81
+ local function bind_keys ()
82
+ vim .g .netrw_nogx = 1 -- disable netrw gx
83
+ local opts = { noremap = true , silent = true }
84
+ vim .keymap .set ({ " n" , " x" }, " gx" , open , opts )
85
+ end
86
+
90
87
-- setup function
91
88
function M .setup (options )
92
89
M .options = with_defaults (options )
93
90
bind_keys ()
94
91
vim .api .nvim_create_user_command (" Browse" , function (opts )
95
- M .browse (opts .fargs [1 ])
92
+ M .browse (" v " , opts .fargs [1 ])
96
93
end , { nargs = 1 })
97
94
end
98
95
0 commit comments