feat: support OpenInGHFileLines command

This commit is contained in:
Ali Almohaya 2023-05-26 22:31:02 +03:00
parent 374c081409
commit b9daa9db78
No known key found for this signature in database
GPG key ID: 4B80BC43FC6007E0
3 changed files with 19 additions and 2 deletions

View file

@ -40,7 +40,10 @@ end)
- Opens the project's git repository page in GitHub. - Opens the project's git repository page in GitHub.
- `:OpenInGHFile` - `:OpenInGHFile`
- Opens the current file page in GitHub. This command supports ranges. - Opens the current file page in GitHub. This command supports ranges.
- `:OpenInGHFileLines`
- Opens the current file page in GitHub. This command supports ranges.
## Usage ## Usage
@ -52,7 +55,7 @@ vim.api.nvim_set_keymap("n", "<Leader>gr", ":OpenInGHRepo <CR>", { silent = true
-- for current file page -- for current file page
vim.api.nvim_set_keymap("n", "<Leader>gf", ":OpenInGHFile <CR>", { silent = true, noremap = true }) vim.api.nvim_set_keymap("n", "<Leader>gf", ":OpenInGHFile <CR>", { silent = true, noremap = true })
vim.api.nvim_set_keymap("v", "<Leader>gf", ":OpenInGHFile <CR>", { silent = true, noremap = true }) vim.api.nvim_set_keymap("v", "<Leader>gf", ":OpenInGHFileLines <CR>", { silent = true, noremap = true })
``` ```
## TODO ## TODO

View file

@ -45,6 +45,10 @@ function M.open_file(
local file_page_url = M.repo_url .. "/blob/" .. utils.get_current_branch_or_commit() .. file_path local file_page_url = M.repo_url .. "/blob/" .. utils.get_current_branch_or_commit() .. file_path
if range_start and not range_end then
file_page_url = file_page_url .. "#L" .. range_start
end
if range_start and range_end then if range_start and range_end then
file_page_url = file_page_url .. "#L" .. range_start .. "-L" .. range_end file_page_url = file_page_url .. "#L" .. range_start .. "-L" .. range_end
end end

View file

@ -15,6 +15,16 @@ end, {
range = true, range = true,
}) })
vim.api.nvim_create_user_command("OpenInGHFileLines", function(opts)
if opts.range == 0 then -- Nothing was selected
openingh.open_file(opts.line1)
else -- Current line or block was selected
openingh.open_file(opts.line1, opts.line2)
end
end, {
range = true,
})
vim.api.nvim_create_user_command("OpenInGHRepo", function() vim.api.nvim_create_user_command("OpenInGHRepo", function()
openingh.open_repo() openingh.open_repo()
end, {}) end, {})