From b4aad6dc43660db554bba2942026fb9965f1a45e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 16 Jul 2021 00:59:35 -0400 Subject: [PATCH] Support ssh.github.com Let's use this opportunity to throw out the old, contorted regexp builder and start over. Resolves: https://github.com/tpope/vim-rhubarb/issues/65 --- autoload/rhubarb.vim | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/autoload/rhubarb.vim b/autoload/rhubarb.vim index 4c3ed23..2a1d54d 100644 --- a/autoload/rhubarb.vim +++ b/autoload/rhubarb.vim @@ -24,19 +24,24 @@ function! s:shellesc(arg) abort endfunction function! rhubarb#HomepageForUrl(url) abort - let domain_pattern = 'github\.com' let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', [])) - for domain in domains - let domain_pattern .= '\|' . escape(split(substitute(domain, '/$', '', ''), '://')[-1], '.') - endfor - let base = matchstr(a:url, '^\%(https\=://\%([^@/:]*@\)\=\|git://\|git@\|ssh://git@\|org-\d\+@\|ssh://org-\d\+@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=/\=$') - if index(domains, 'http://' . matchstr(base, '^[^:/]*')) >= 0 - return 'http://' . tr(base, ':', '/') - elseif !empty(base) - return 'https://' . tr(base, ':', '/') + if a:url =~# '://' + let match = matchlist(a:url, '^\(https\=://\%([^@/:]*@\)\=\|git://\|ssh://git@\|ssh://org-\d\+@\)\([^/]\+\)/\(.\{-\}\)\%(\.git\)\=/\=$') + else + let match = matchlist(a:url, '^\(git@\|org-\d\+@\)\([^:/]\+\):\(.\{-\}\)\%(\.git\)\=/\=$') + endif + if empty(match) + return '' + elseif match[2] ==# 'github.com' || match[2] =~# '^ssh\.github\.com\%(:443\)\=$' + let root = 'https://github.com' + elseif index(domains, 'http://' . match[2]) >= 0 || index(domains, match[2]) >= 0 && match[1] =~# '^http://' + let root = 'http://' . match[2] + elseif index(domains, 'https://' . match[2]) >= 0 || index(domains, match[2]) >= 0 + let root = 'https://' . match[2] else return '' endif + return root . '/' . match[3] endfunction function! rhubarb#homepage_for_url(url) abort