diff --git a/README.md b/README.md index 6253857..e264694 100644 --- a/README.md +++ b/README.md @@ -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, ..) @@ -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 }, diff --git a/lua/gx/handler.lua b/lua/gx/handler.lua index d5c3374..c15ca49 100644 --- a/lua/gx/handler.lua +++ b/lua/gx/handler.lua @@ -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") @@ -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) diff --git a/lua/gx/handlers/brewfile.lua b/lua/gx/handlers/brewfile.lua new file mode 100644 index 0000000..625fe01 --- /dev/null +++ b/lua/gx/handlers/brewfile.lua @@ -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 diff --git a/lua/gx/init.lua b/lua/gx/init.lua index ab7abc1..69ccdc4 100644 --- a/lua/gx/init.lua +++ b/lua/gx/init.lua @@ -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(