Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lua/nvim-github-linker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might not need this, it is supported by the long substitute string match.

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
Expand Down Expand Up @@ -68,7 +69,6 @@ function M.github_linker_command()
else
print(url)
end

end

return M