From b9daa9db78c5a5586b637c0f309c5e9c502ed508 Mon Sep 17 00:00:00 2001 From: Ali Almohaya Date: Fri, 26 May 2023 22:31:02 +0300 Subject: [PATCH] feat: support OpenInGHFileLines command --- README.md | 7 +++++-- lua/openingh/init.lua | 4 ++++ plugin/openingh.lua | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd428e9..9484289 100644 --- a/README.md +++ b/README.md @@ -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", "gr", ":OpenInGHRepo ", { silent = true -- for current file page vim.api.nvim_set_keymap("n", "gf", ":OpenInGHFile ", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("v", "gf", ":OpenInGHFile ", { silent = true, noremap = true }) +vim.api.nvim_set_keymap("v", "gf", ":OpenInGHFileLines ", { silent = true, noremap = true }) ``` ## TODO diff --git a/lua/openingh/init.lua b/lua/openingh/init.lua index 1078d90..c2e9884 100644 --- a/lua/openingh/init.lua +++ b/lua/openingh/init.lua @@ -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 diff --git a/plugin/openingh.lua b/plugin/openingh.lua index 51ea601..a40e828 100644 --- a/plugin/openingh.lua +++ b/plugin/openingh.lua @@ -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, {})