Skip to content

Commit

Permalink
gx: [n] open url 지원
Browse files Browse the repository at this point in the history
  • Loading branch information
deptno committed Oct 15, 2023
1 parent 7534f8a commit c366ead
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/lab/gx/handlers_n/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
return {
require('lab/gx/handlers_n/url'),
require('lab/gx/handlers_n/jira_issue'),
require('lab/gx/handlers_n/neogit_log'),
require('lab/gx/handlers_n/github_commit'),
Expand Down
20 changes: 20 additions & 0 deletions lua/lab/gx/handlers_n/url.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local get_url = require('lab/gx/lib/get_url')
local handler = function (line, matched)
local os = vim.loop.os_uname().sysname
if vim.loop.os_uname().sysname ~= 'Darwin' then
return vim.notify('unsupported os: ' .. os, vim.log.levels.WARN)
end

local command = string.format('open %s', matched)
vim.fn.system(command)
vim.notify(command)
end
local match = get_url
local name = 'url'

return {
handler = handler,
match = match,
name = name,
}

10 changes: 10 additions & 0 deletions lua/lab/gx/lib/get_url.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---라인 매칭에서 매칭 수행 반환은 url
---@param input string
---@return string|nil
local get_url = function (input)
local pattern = ".*(https?://[%w-_%.%?%.:/%+=&]+).*"

return input:match(pattern)
end

return get_url

0 comments on commit c366ead

Please sign in to comment.