Merge pull request #18 from Almo7aya/feat/add_OpenInGHFileLines_commands

This commit is contained in:
Ali Almohaya 2023-06-17 04:35:07 +03:00 committed by GitHub
commit fcf648628d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.
- `: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
@ -52,7 +55,7 @@ vim.api.nvim_set_keymap("n", "<Leader>gr", ":OpenInGHRepo <CR>", { silent = true
-- for current file page
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

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
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
file_page_url = file_page_url .. "#L" .. range_start .. "-L" .. range_end
end

View file

@ -15,6 +15,16 @@ end, {
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()
openingh.open_repo()
end, {})