diff --git a/lua/openingh/init.lua b/lua/openingh/init.lua index dbda762..dfb8ad9 100644 --- a/lua/openingh/init.lua +++ b/lua/openingh/init.lua @@ -1,3 +1,5 @@ +local remote_format = "%s/blob/%s/%s" +local bb_remote_format = "%s/src/%s/%s" local utils = require("openingh.utils") local M = {} @@ -12,14 +14,14 @@ function M.setup() return end - local gh = utils.parse_gh_remote(repo_url) - if gh == nil then - print("Error parsing GitHub remote URL") + local remote = utils.parse_remote(repo_url) + if remote == nil then + print("Error parsing remote URL") vim.g.openingh = false return end - M.repo_url = string.format("http://%s/%s/%s", gh.host, gh.user_or_org, gh.reponame) + M.repo_url = string.format("http://%s/%s/%s", remote.host, remote.user_or_org, remote.reponame) end M.priority = { BRANCH = 1, COMMIT = 2 } @@ -63,7 +65,13 @@ function M.get_file_url( rev = branch end - local file_page_url = M.repo_url .. "/blob/" .. rev .. file_path + local file_page_url = "" + + if string.find(M.repo_url, "bitbucket") then + file_page_url = string.format(bb_remote_format, M.repo_url, rev, file_path) + else + file_page_url = string.format(remote_format, M.repo_url, rev, file_path) + end if range_start and not range_end then file_page_url = file_page_url .. "#L" .. range_start diff --git a/lua/openingh/utils.lua b/lua/openingh/utils.lua index e1f8ae5..5164453 100644 --- a/lua/openingh/utils.lua +++ b/lua/openingh/utils.lua @@ -32,7 +32,7 @@ end -- returns a table with the host, user/org and the reponame given a github remote url -- nil is returned when the url cannot be parsed -function M.parse_gh_remote(url) +function M.parse_remote(url) -- 3 capture groups for host, org/user and repo. whitespace is trimmed -- when cloning with http://, gh redirects to https://, but remote stays http local http = { string.find(url, "https?://([^/]*)/([^/]*)/([^%s/]*)") }