From cbf7e4d88ee1795a2020d74d048e09ee015eabc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vegard=20Bj=C3=B8rsvik?= Date: Mon, 25 Sep 2023 16:37:15 +0200 Subject: [PATCH 1/2] Added some substitution so it works with enterprise ssh urls --- lua/nvim-github-linker.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/nvim-github-linker.lua b/lua/nvim-github-linker.lua index 22548a3..ca1cf89 100644 --- a/lua/nvim-github-linker.lua +++ b/lua/nvim-github-linker.lua @@ -16,7 +16,7 @@ function M.setup(opts) vim.g.nvim_github_linker_copy_to_clipboard = options.copy_to_clipboard if options.mappings then - vim.cmd([[command! -range GithubLink lua require('nvim-github-linker').github_linker_command(,)]]) + vim.cmd([[command! -range GithubLink2 lua require('nvim-github-linker').github_linker_command(,)]]) end end @@ -28,10 +28,11 @@ function M.github_linker(start_line, end_line) local project_root = vim.fn.systemlist('git rev-parse --show-toplevel')[1] local relative_path = vim.fn.fnamemodify(current_file, ':gs?' .. project_root .. '??') - local repo_url = vim.fn.systemlist("git config --get remote." .. vim.g.nvim_github_linker_default_remote .. ".url")[ - 1] - local repo_path = vim.fn.substitute(repo_url, '\\(.*github.com\\)\\(:\\|/\\)\\([^/]*\\)/\\(.*\\)\\.git', - 'https://github.com/\\3/\\4', '') + local raw_repo_url = vim.fn.systemlist("git config --get remote." .. + vim.g.nvim_github_linker_default_remote .. ".url")[1] + local repo_url = raw_repo_url:gsub(':', '/'):gsub('git@', 'https://'):gsub('%.git', '') + local repo_path = vim.fn.substitute(repo_url, '\\(.*github.com\\)\\(/\\)\\([^/]*\\)/\\(.*\\)\\.git', '\\1\\2\\3/\\4', + '') local branch_name = vim.fn.systemlist("git symbolic-ref --short HEAD")[1] local base_url = repo_path .. '/blob/' .. branch_name local range = 'L' .. line_number @@ -68,7 +69,6 @@ function M.github_linker_command() else print(url) end - end return M From 407732eca2cb1c1f5e3571e4e5022bfbc040dbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vegard=20Bj=C3=B8rsvik?= Date: Mon, 25 Sep 2023 16:38:34 +0200 Subject: [PATCH 2/2] Remove test command name --- lua/nvim-github-linker.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-github-linker.lua b/lua/nvim-github-linker.lua index ca1cf89..dd5c307 100644 --- a/lua/nvim-github-linker.lua +++ b/lua/nvim-github-linker.lua @@ -16,7 +16,7 @@ function M.setup(opts) vim.g.nvim_github_linker_copy_to_clipboard = options.copy_to_clipboard if options.mappings then - vim.cmd([[command! -range GithubLink2 lua require('nvim-github-linker').github_linker_command(,)]]) + vim.cmd([[command! -range GithubLink lua require('nvim-github-linker').github_linker_command(,)]]) end end