mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-07 20:54:27 +08:00
Set omnifunc in GitHub Enterprise repositories
This commit is contained in:
@@ -23,30 +23,34 @@ function! s:shellesc(arg) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:homepage_for_url(url) abort
|
function! rhubarb#homepage_for_url(url) abort
|
||||||
let domain_pattern = 'github\.com'
|
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', []))
|
||||||
call map(copy(domains), 'substitute(v:val, "/$", "", "")')
|
call map(copy(domains), 'substitute(v:val, "/$", "", "")')
|
||||||
for domain in domains
|
for domain in domains
|
||||||
let domain_pattern .= '\|' . escape(split(domain, '://')[-1], '.')
|
let domain_pattern .= '\|' . escape(split(domain, '://')[-1], '.')
|
||||||
endfor
|
endfor
|
||||||
let repo = fugitive#buffer().repo()
|
|
||||||
let base = matchstr(a:url, '^\%(https\=://\|git://\|git@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
|
let base = matchstr(a:url, '^\%(https\=://\|git://\|git@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
|
||||||
if index(domains, 'http://' . matchstr(base, '^[^:/]*')) >= 0
|
if index(domains, 'http://' . matchstr(base, '^[^:/]*')) >= 0
|
||||||
return 'http://' . tr(base, ':', '/')
|
return 'http://' . tr(base, ':', '/')
|
||||||
elseif !empty(base)
|
elseif !empty(base)
|
||||||
return 'https://' . tr(base, ':', '/')
|
return 'https://' . tr(base, ':', '/')
|
||||||
|
else
|
||||||
|
return ''
|
||||||
endif
|
endif
|
||||||
call s:throw('not a GitHub repository: '.a:url)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_homepage() abort
|
function! s:repo_homepage() abort
|
||||||
if !exists('b:rhubarb_homepage')
|
if exists('b:rhubarb_homepage')
|
||||||
let repo = fugitive#buffer().repo()
|
|
||||||
let url = repo.config('remote.origin.url')
|
|
||||||
let b:rhubarb_homepage = s:homepage_for_url(url)
|
|
||||||
endif
|
|
||||||
return b:rhubarb_homepage
|
return b:rhubarb_homepage
|
||||||
|
endif
|
||||||
|
let repo = fugitive#repo()
|
||||||
|
let homepage = rhubarb#homepage_for_url(repo.config('remote.origin.url'))
|
||||||
|
if !empty(homepage)
|
||||||
|
let b:rhubarb_homepage = homepage
|
||||||
|
return b:rhubarb_homepage
|
||||||
|
endif
|
||||||
|
call s:throw('origin is not a GitHub repository')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: HTTP
|
" Section: HTTP
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ augroup rhubarb
|
|||||||
\ if expand('%:p') =~# '\.git[\/].*MSG$' &&
|
\ if expand('%:p') =~# '\.git[\/].*MSG$' &&
|
||||||
\ exists('+omnifunc') &&
|
\ exists('+omnifunc') &&
|
||||||
\ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' &&
|
\ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' &&
|
||||||
\ join(readfile(fugitive#buffer().repo().dir('config')),"\n")
|
\ !empty(filter(
|
||||||
\ =~# '\n[^;]*github\.com' |
|
\ readfile(fugitive#buffer().repo().dir('config')),
|
||||||
|
\ '!empty(rhubarb#homepage_for_url(matchstr(v:val, ''^\s*url\s*=\s*"\=\zs\S*'')))')) |
|
||||||
\ setlocal omnifunc=rhubarb#omnifunc |
|
\ setlocal omnifunc=rhubarb#omnifunc |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd BufEnter *
|
autocmd BufEnter *
|
||||||
|
|||||||
Reference in New Issue
Block a user