Skip to content

Commit 5649887

Browse files
authored
feat: Override vim.ui.open for http urls (#35)
Closes #34
1 parent 8b39875 commit 5649887

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/client/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ vim.api.nvim_create_user_command(
497497
}
498498
)
499499
return true
500-
`, nil, nil)
500+
`, nil)
501501

502502
// Add command to open url.
503503
batch.ExecLua(`
@@ -511,7 +511,7 @@ vim.api.nvim_create_user_command(
511511
force = true,
512512
}
513513
)
514-
`, nil, nil)
514+
`, nil)
515515

516516
// Prepare the browser script.
517517
batch.ExecLua(`
@@ -533,6 +533,18 @@ os.execute('chmod +x ' .. browser_script_path)
533533
return true
534534
`, nil, nvrhContext.BrowserScriptPath, nvrhContext.RemoteSocketOrPort(), nv.ChannelID())
535535

536+
batch.ExecLua(`
537+
local original_open = vim.ui.open
538+
vim.ui.open = function(uri, opts)
539+
if type(uri) == 'string' and uri:match('^https?://') then
540+
vim.rpcnotify(tonumber(os.getenv('NVRH_CHANNEL_ID')), 'open-url', { uri })
541+
return nil, nil
542+
else
543+
return original_open(uri, opts)
544+
end
545+
end
546+
`, nil)
547+
536548
if err := batch.Execute(); err != nil {
537549
return err
538550
}

0 commit comments

Comments
 (0)