10000 load gx.nvim lazy by chrishrb · Pull Request #37 · chrishrb/gx.nvim · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

load gx.nvim lazy #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
require("lazy").setup({
{
"chrishrb/gx.nvim",
event = { "BufEnter" },
keys = { {"gx", mode = { "n", "x" }} },
cmd = { "Browse" },
init = function ()
vim.g.netrw_nogx = 1 -- disable netrw gx
end,
dependencies = { "nvim-lua/plenary.nvim" },
config = true, -- default settings

Expand All @@ -53,9 +57,10 @@ require("lazy").setup({
})
```

## ⌨️ Mappings
## ⌨️ Mappings and Commands

* `gx` is overridden by default
* `Browse <URL or WORDS>`, e.g. `Browse http://google.de`, `Browse example`

## 🚀 Usage

Expand Down
35 changes: 16 additions & 19 deletions lua/gx/init.lua
9A10
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
local helper = require("gx.helper")

local keymap = vim.keymap.set
local sysname = vim.loop.os_uname().sysname

local M = {}

-- search for url with handler
local function search_for_url()
local line = vim.api.nvim_get_current_line()
local mode = vim.api.nvim_get_mode().mode

-- cut if in visual mode
line = helper.cut_with_visual_mode(mode, line)

function M.browse(mode, line)
-- search for url
local url =
require("gx.handler").get_url(mode, line, M.options.handlers, M.options.handler_options)
Expand All @@ -21,23 +13,22 @@ local function search_for_url()
return
end

return M.browse(url)
end

function M.browse(url)
return require("gx.shell").execute_with_error(
M.options.open_browser_app,
M.options.open_browser_args,
url
)
end

-- create keybindings
local function bind_keys()
vim.g.netrw_nogx = 1 -- disable netrw gx
-- search for url with handler
local function open()
local line = vim.api.nvim_get_current_line()
local mode = vim.api.nvim_get_mode().mode

local opts = { noremap = true, silent = true }
keymap({ "n", "x" }, "gx", search_for_url, opts)
-- cut if in visual mode
line = helper.cut_with_visual_mode(mode, line)

return M.browse(mode, line)
end

-- get the app for opening the webbrowser
Expand Down Expand Up @@ -87,12 +78,18 @@ local function with_defaults(options)
}
end

local function bind_keys()
vim.g.netrw_nogx = 1 -- disable netrw gx
local opts = { noremap = true, silent = true }
vim.keymap.set({ "n", "x" }, "gx", open, opts)
end

-- setup function
function M.setup(options)
M.options = with_defaults(options)
bind_keys()
vim.api.nvim_create_user_command("Browse", function(opts)
M.browse(opts.fargs[1])
M.browse("v", opts.fargs[1])
end, { nargs = 1 })
end

Expand Down
0