diff --git a/lazy-lock.json b/lazy-lock.json index 0b5ed14..0bc8edd 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -13,6 +13,7 @@ "fidget.nvim": { "branch": "main", "commit": "4e854f3299e21d1c18279add340428a97520fc44" }, "friendly-snippets": { "branch": "main", "commit": "dbd45e9ba76d535e4cba88afa1b7aa43bb765336" }, "gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" }, + "gx-extended.nvim": { "branch": "dev", "commit": "6f6e078a628014b087997d25e242df1eb013c3b6" }, "hardtime.nvim": { "branch": "main", "commit": "860e912895176112868c97b46277f547e149f5e6" }, "highlight-undo.nvim": { "branch": "main", "commit": "50a6884a8476be04ecce8f1c4ed692c5000ef0a1" }, "hlchunk.nvim": { "branch": "main", "commit": "882d1bc86d459fa8884398223c841fd09ea61b6b" }, @@ -41,8 +42,6 @@ "nvim-treesitter-textobjects": { "branch": "master", "commit": "7f00d94543f1fd37cab2afa2e9a6cd54e1c6b9ef" }, "nvim-web-devicons": { "branch": "master", "commit": "14ac5887110b06b89a96881d534230dac3ed134d" }, "nvim-window": { "branch": "main", "commit": "e7f5d60eeec8ff37af7be4c9a99f65edf67fc574" }, - "open-browser-github.vim": { "branch": "master", "commit": "ac7c034e300f36d591ef234dcd5eb5cd5c07c74f" }, - "open-browser.vim": { "branch": "master", "commit": "7d4c1d8198e889d513a030b5a83faa07606bac27" }, "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, "project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" }, "rest.nvim": { "branch": "main", "commit": "c27a0bcb84ab5534d89065d638119ed2dbbae189" }, diff --git a/lua/plugins/common.lua b/lua/plugins/common.lua index 85d499a..ab3d81a 100644 --- a/lua/plugins/common.lua +++ b/lua/plugins/common.lua @@ -91,13 +91,6 @@ return { event = 'VeryLazy', config = true, }, - { - 'tyru/open-browser.vim', - event = 'VeryLazy', - config = function() - vim.cmd([[ nmap gx (openbrowser-open) ]]) - end, - }, { 'akinsho/toggleterm.nvim', event = 'BufReadPost', diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua index 590826a..655be98 100644 --- a/lua/plugins/git.lua +++ b/lua/plugins/git.lua @@ -56,13 +56,6 @@ return { { 'gh', mode = { 'n', 'x' } }, }, }, - { - 'tyru/open-browser-github.vim', - cmd = 'OpenGithubIssue', - dependencies = { - 'tyru/open-browser.vim', - }, - }, { 'sindrets/diffview.nvim', cmd = { diff --git a/lua/plugins/gx.lua b/lua/plugins/gx.lua new file mode 100644 index 0000000..89bfea0 --- /dev/null +++ b/lua/plugins/gx.lua @@ -0,0 +1,134 @@ +return { + 'reegnz/gx-extended.nvim', + branch = 'dev', + keys = { + { 'gx', mode = { 'n', 'x' } }, + }, + opts = { + open_fn = require('lazy.util').open, + -- log_level = vim.log.levels.DEBUG, + extensions = { + { + -- ABC-123 ABC-56 + -- vim.g.gx_jira_url = https://jira.example.com/browse/ + name = 'Open JIRA Issue', + match_to_url = function(line_string) + local gx_jira_url = vim.g.gx_jira_url or os.getenv('WORK_JIRA_URL') + if not gx_jira_url then + return nil + end + local col = vim.fn.col('.') + local match_start + --- @type integer|nil + local match_end = 1 + local ticket + while true do + match_start, match_end, ticket = string.find(line_string, '(%a+-%d+)', match_end) + if not ticket then + return nil + end + if match_start <= col and match_end >= col then + break + end + end + return gx_jira_url .. ticket + end, + }, + { + name = 'Google Search in Visual Mode', + match_to_url = function() + local mode = vim.api.nvim_get_mode().mode + local is_visual = mode:match('[vV\x16]') + -- only trigger searches for visual selection + if not is_visual then + return nil + end + local vstart = vim.fn.getpos('v') + local vend = vim.fn.getpos('.') + if vstart[2] > vend[2] then + vstart, vend = vend, vstart + end + if vstart[2] == vend[2] and vstart[3] > vend[3] then + vstart, vend = vend, vstart + end + local lines = vim.api.nvim_buf_get_lines(0, vstart[2] - 1, vend[2], true) + if #lines == 0 then + return nil + end + lines[#lines] = string.sub(lines[#lines], 1, vend[3]) + lines[1] = string.sub(lines[1], vstart[3]) + local query = table.concat(lines, ' ') + return 'https://google.com/search?q=' .. query + end, + }, + { + name = 'Open Markdown Link', + filetypes = { 'markdown' }, + match_to_url = function(line_string) + local cursor = vim.fn.getpos('.') + local match = vim.fn.matchstrpos(line_string, '\\[.+\\]\\((.+)\\)', cursor[3]) + if cursor[3] < match[2] or cursor[3] > match[3] then + -- cursor is not within pattern + return + end + line_string:sub(match[2], match[3] + 1) + local url = line_string:match('%[%]%(.+)%)') + if url then + return url + end + return nil + end, + }, + { + name = 'Open GitHub issue', + match_to_url = function(line_string) + if not vim.fn.executable('gh') then + return nil + end + local col = vim.fn.col('.') + local match_start, match_end, issue = string.find(line_string, '#(%d+)') + if not issue or match_start > col or match_end < col then + return nil + end + local cmd = string.format('gh issue view %s --json url --jq .url', issue) + local lines + local job = vim.fn.jobstart(cmd, { + stdout_buffered = true, + on_stdout = function(_, __lines) + lines = __lines + end, + }) + vim.fn.jobwait({ job }) + return lines[1] + end, + }, + { + name = 'Open brew formula/cask', + filenames = { 'Brewfile' }, + match_to_url = function(line_string) + local _, _, brew = string.find(line_string, 'brew ["]([^%s]+)["]') + if brew then + return 'https://formulae.brew.sh/formula/' .. brew + end + local _, _, cask = string.find(line_string, 'cask ["]([^%s]+)["]') + if cask then + return 'https://formulae.brew.sh/cask/' .. cask + end + return nil + end, + }, + { + name = 'Open lazy.nvim plugin', + patterns = { '*/.config/nvim/**/*.lua', '*/.local/share/nvim/lazy/LazyVim/lua/lazyvim/**/*.lua' }, + filetypes = { 'lua' }, + match_to_url = function(line_string) + local _, _, repo = string.find(line_string, "[\"'']([^%s~/]+/[^%s~/]+)[\"'']") + if not repo then + return nil + end + return 'https://github.com/' .. repo + end, + }, + }, + }, +}