Skip to content
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

Add brewfile handler #23

Merged
merged 2 commits into from
May 31, 2023
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* open plugins in the browser with a single command (e.g. in lazy, packer you can hover over a plugin name, simply press `gx` and you get to the github page of the plugin)
* open github issues directly in the browser (e.g. `Fixes #22` opens `https://github.com/chrishrb/gx.nvim/issues/22`)
* dependencies from `package.json` (e.g. line `"express": "^4.18.2",` in the `package.json` opens `https://www.npmjs.com/package/express`)
* formulae and casks from `Brewfile` (e.g. line `brew "neovim"` in the `Brewfile` opens `https://formulae.brew.sh/formula/neovim`)
* if there is no url found under the cursor, the word/selection is automatically searched on the web
* support for macOS, Linux and Windows
* more to come (jira issues, ..)
Expand Down Expand Up @@ -39,6 +40,7 @@ require("lazy").setup({
handlers = {
plugin = true, -- open plugin links in lua (e.g. packer, lazy, ..)
github = true, -- open github issues
brewfile = true, -- open Homebrew formulaes and casks
package_json = true, -- open dependencies from package.json
search = true, -- search the web/selection on the web if nothing else is found
},
Expand Down
2 changes: 2 additions & 0 deletions lua/gx/handler.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local helper = require("gx.helper")
local brewfile_handler = require("gx.handlers.brewfile")
local package_json_handler = require("gx.handlers.package_json")
local plugin_handler = require("gx.handlers.plugin")
local url_handler = require("gx.handlers.url")
Expand Down Expand Up @@ -27,6 +28,7 @@ function M.get_url(mode, line, activated_handlers, handler_options)
local tkeys = {}

-- ### add here new handlers
add_handler(handlers, brewfile_handler, activated_handlers.brewfile)
add_handler(handlers, package_json_handler, activated_handlers.package_json)
add_handler(handlers, plugin_handler, activated_handlers.plugin)
add_handler(handlers, github_handler, activated_handlers.github)
Expand Down
23 changes: 23 additions & 0 deletions lua/gx/handlers/brewfile.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local helper = require("gx.helper")

local M = {}

-- only Brewfile
M.filetype = nil
M.filename = "Brewfile"

-- navigate to Homebrew Formulae url
function M.handle(mode, line, _)
local brew_pattern = 'brew ["]([^%s]*)["]'
local cask_pattern = 'cask ["]([^%s]*)["]'
local brew = helper.find(line, mode, brew_pattern)
local cask = helper.find(line, mode, cask_pattern)
if brew then
return "https://formulae.brew.sh/formula/" .. brew
end
if cask then
return "https://formulae.brew.sh/cask/" .. cask
end
end

return M
1 change: 1 addition & 0 deletions lua/gx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ local function with_defaults(options)
open_browser_app = options.open_browser_app or get_open_browser_app(),
open_browser_args = get_open_browser_args(options.open_browser_args or {}),
handlers = {
brewfile = helper.ternary(options.handlers.brewfile ~= nil, options.handlers.brewfile, true),
plugin = helper.ternary(options.handlers.plugin ~= nil, options.handlers.plugin, true),
github = helper.ternary(options.handlers.github ~= nil, options.handlers.github, true),
package_json = helper.ternary(
Expand Down