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
This commit is contained in:
Tim Pope
2021-07-16 00:59:35 -04:00
parent 2590324d7f
commit b4aad6dc43

View File

@@ -24,19 +24,24 @@ function! s:shellesc(arg) abort
endfunction endfunction
function! rhubarb#HomepageForUrl(url) abort function! rhubarb#HomepageForUrl(url) abort
let domain_pattern = 'github\.com'
let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', [])) let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', []))
for domain in domains if a:url =~# '://'
let domain_pattern .= '\|' . escape(split(substitute(domain, '/$', '', ''), '://')[-1], '.') let match = matchlist(a:url, '^\(https\=://\%([^@/:]*@\)\=\|git://\|ssh://git@\|ssh://org-\d\+@\)\([^/]\+\)/\(.\{-\}\)\%(\.git\)\=/\=$')
endfor else
let base = matchstr(a:url, '^\%(https\=://\%([^@/:]*@\)\=\|git://\|git@\|ssh://git@\|org-\d\+@\|ssh://org-\d\+@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=/\=$') let match = matchlist(a:url, '^\(git@\|org-\d\+@\)\([^:/]\+\):\(.\{-\}\)\%(\.git\)\=/\=$')
if index(domains, 'http://' . matchstr(base, '^[^:/]*')) >= 0 endif
return 'http://' . tr(base, ':', '/') if empty(match)
elseif !empty(base) return ''
return 'https://' . tr(base, ':', '/') 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 else
return '' return ''
endif endif
return root . '/' . match[3]
endfunction endfunction
function! rhubarb#homepage_for_url(url) abort function! rhubarb#homepage_for_url(url) abort