openingh.nvim/plugin/openingh.lua

72 lines
1.7 KiB
Lua
Raw Normal View History

2022-09-25 23:30:27 +03:00
if vim.g.openingh then
return
2022-09-25 23:30:27 +03:00
end
vim.g.openingh = true
2022-10-16 00:28:16 -04:00
local openingh = require("openingh")
2022-09-26 23:53:18 +03:00
2023-09-23 10:07:01 +09:00
local function judge_priority(bang)
-- When the command executed with bang `!`, prioritizes commit rather than branch.
if bang then
return openingh.priority.COMMIT
else
return openingh.priority.BRANCH
end
end
vim.api.nvim_create_user_command("OpenInGHFile", function(opts)
local url
if opts.range == 0 then -- Nothing was selected
2023-09-23 10:07:01 +09:00
url = openingh.get_file_url(judge_priority(opts.bang))
else -- Current line or block was selected
2023-09-23 10:07:01 +09:00
url = openingh.get_file_url(judge_priority(opts.bang), opts.line1, opts.line2)
end
2023-08-26 23:00:22 +02:00
if opts.reg == "" then
openingh.open_url(url)
else
vim.fn.setreg(opts.reg, url)
2023-08-27 11:18:00 +02:00
print("URL put into register " .. opts.reg)
2023-08-26 23:00:22 +02:00
end
end, {
2023-08-26 23:00:22 +02:00
register = true,
range = true,
2023-09-23 10:07:01 +09:00
bang = true,
})
2022-09-25 23:30:27 +03:00
vim.api.nvim_create_user_command("OpenInGHFileLines", function(opts)
local url
if opts.range == 0 then -- Nothing was selected
2023-09-23 10:07:01 +09:00
url = openingh.get_file_url(judge_priority(opts.bang), opts.line1)
else -- Current line or block was selected
2023-09-23 10:07:01 +09:00
url = openingh.get_file_url(judge_priority(opts.bang), opts.line1, opts.line2)
end
2023-08-26 23:00:22 +02:00
if opts.reg == "" then
openingh.open_url(url)
else
vim.fn.setreg(opts.reg, url)
2023-08-27 11:18:00 +02:00
print("URL put into register " .. opts.reg)
2023-08-26 23:00:22 +02:00
end
end, {
2023-08-26 23:00:22 +02:00
register = true,
range = true,
2023-09-23 10:07:01 +09:00
bang = true,
})
2023-06-18 06:48:17 +09:00
vim.api.nvim_create_user_command("OpenInGHRepo", function(opts)
2023-09-23 10:07:01 +09:00
local url = openingh.get_repo_url(judge_priority(opts.bang))
2023-08-26 23:00:22 +02:00
if opts.reg == "" then
openingh.open_url(url)
else
vim.fn.setreg(opts.reg, url)
2023-08-27 11:18:00 +02:00
print("URL put into register " .. opts.reg)
2023-08-26 23:00:22 +02:00
end
end, {
2023-08-26 23:00:22 +02:00
register = true,
2023-09-23 10:07:01 +09:00
bang = true,
})