mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[nvim] add a GBrowse handler for AUR package repos
This commit is contained in:
parent
8804edfafe
commit
02cee81a90
4 changed files with 99 additions and 3 deletions
84
nvim/autoload/dotfiles/fugitive/aur.vim
Normal file
84
nvim/autoload/dotfiles/fugitive/aur.vim
Normal file
|
@ -0,0 +1,84 @@
|
|||
" Based on <https://github.com/tpope/vim-rhubarb/blob/3d444b5b4f636408c239a59adb88ee13a56486e0/autoload/rhubarb.vim>
|
||||
" Also see <https://github.com/tpope/vim-fugitive/blob/0868c30cc08a4cf49b5f43e08412c671b19fa3f0/autoload/fugitive.vim#L6123-L6343>.
|
||||
" Other intersting links:
|
||||
" <https://git.zx2c4.com/cgit/>
|
||||
" <https://github.com/shumphrey/fugitive-gitlab.vim/blob/f3e56ff60fe3fb5ebc891cbe5fd12cd8c59ae6ef/autoload/gitlab.vim#L6-L93>
|
||||
" <https://github.com/tommcdo/vim-fubitive/blob/5717417ee75c39ea2f8f446a9491cdf99d5965e9/plugin/fubitive.vim>
|
||||
" <https://github.com/LinuxSuRen/fugitive-gitee.vim/blob/96221852753a04daeb8136c54b0082db36d1ac5b/plugin/gitee.vim>
|
||||
" <https://github.com/jparise/vim-phabricator/blob/d5c0571f44f2c44ba32df2d12e52b4dfcd4921ed/autoload/phabricator.vim>
|
||||
" <https://github.com/cedarbaum/fugitive-azure-devops.vim/blob/4f1adeac33f54d1ec1949364d049237d7485dea1/autoload/azuredevops.vim>
|
||||
function! dotfiles#fugitive#aur#handler(opts) abort
|
||||
if type(a:opts) != v:t_dict
|
||||
return ''
|
||||
endif
|
||||
let opts = a:opts
|
||||
|
||||
let parsed = dotfiles#fugitive#aur#parse_url(get(opts, 'remote', ''))
|
||||
if empty(parsed)
|
||||
return ''
|
||||
endif
|
||||
|
||||
let path = substitute(opts.path, '^/', '', '')
|
||||
if path =~# '^\.git/refs/heads/'
|
||||
let branch = path[16:-1]
|
||||
" AUR packages can have only a single branch, master, as it is mapped to
|
||||
" the branch named after the package in the central Git repository.
|
||||
if branch ==# 'master'
|
||||
return parsed.cgit_prefix . '/log/' . parsed.cgit_suffix
|
||||
endif
|
||||
return ''
|
||||
elseif path =~# '^\.git/refs/tags/'
|
||||
" Tags are not allowed for AUR packages.
|
||||
let tag = path[15:-1]
|
||||
return ''
|
||||
elseif path =~# '^\.git/refs/remotes/[^/]\+/.'
|
||||
let remote_branch = matchstr(path[18:-1], '^[^/]\+/\zs.*$')
|
||||
" Same story as with regular branches.
|
||||
if remote_branch ==# 'master'
|
||||
return parsed.cgit_prefix . '/log/' . parsed.cgit_suffix
|
||||
endif
|
||||
return ''
|
||||
elseif path =~# '^\.git/'
|
||||
return parsed.cgit_prefix . '/' . parsed.cgit_suffix
|
||||
endif
|
||||
|
||||
if opts.commit =~# '^\d\=$'
|
||||
return ''
|
||||
elseif expand('%') =~? '^fugitive:'
|
||||
let commit = opts.commit
|
||||
else
|
||||
let commit = a:opts.repo.rev_parse('HEAD')
|
||||
endif
|
||||
|
||||
let line = min([opts.line1, opts.line2])
|
||||
let parsed.cgit_suffix .= '&id=' . substitute(commit, '#', '%23', 'g')
|
||||
if opts.type ==# 'blob' || opts.type ==# 'tree'
|
||||
return parsed.cgit_prefix . '/tree/' . substitute(path, '/$', '', 'g') . parsed.cgit_suffix . (line ? '#n'.line : '')
|
||||
elseif opts.type ==# 'commit' || opts.type ==# 'tag'
|
||||
return parsed.cgit_prefix . '/commit/' . parsed.cgit_suffix
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
|
||||
" Based on <https://github.com/shumphrey/fugitive-gitlab.vim/blob/f3e56ff60fe3fb5ebc891cbe5fd12cd8c59ae6ef/autoload/gitlab.vim#L70-L79>
|
||||
" and <https://github.com/tpope/vim-rhubarb/blob/3d444b5b4f636408c239a59adb88ee13a56486e0/autoload/rhubarb.vim#L32>.
|
||||
" Also see <https://github.com/archlinux/aurweb/blob/d5e308550ad4682829c01feb32212540a6699100/web/html/404.php#L8>.
|
||||
function! dotfiles#fugitive#aur#parse_url(url) abort
|
||||
let intro_re = '%(https=|git|ssh)\://%([^/@]+\@)='
|
||||
let domain_re = 'aur\.archlinux\.org'
|
||||
let repo_path_re = '[a-zA-Z0-9][a-zA-Z0-9_\.\+\-]{-}'
|
||||
let outro_re = '%(\.git)=/='
|
||||
let combined_re = '\v^'.intro_re.'\zs('.domain_re.')/('.repo_path_re.')\ze'.outro_re.'$'
|
||||
let matches = matchlist(a:url, combined_re)
|
||||
if empty(matches)
|
||||
return {}
|
||||
endif
|
||||
let domain = matches[1]
|
||||
let package = matches[2]
|
||||
let homepage = 'https://'.domain.'/pkgbase/'.package
|
||||
let cgit_prefix = 'https://'.domain.'/cgit/aur.git'
|
||||
let cgit_suffix = '?h='.package
|
||||
return {'domain': domain, 'package': package, 'homepage': homepage, 'cgit_prefix': cgit_prefix, 'cgit_suffix': cgit_suffix}
|
||||
endfunction
|
|
@ -2,7 +2,7 @@
|
|||
" A motion for moving over enclosing indentation blocks. Primarily intended
|
||||
" for reverse-engineering CrossCode.
|
||||
|
||||
function dotfiles#indent_motion#run(direction) abort
|
||||
function! dotfiles#indent_motion#run(direction) abort
|
||||
let cursor_linenr = line(".")
|
||||
let max_linenr = line("$")
|
||||
|
||||
|
@ -55,7 +55,7 @@ function dotfiles#indent_motion#run(direction) abort
|
|||
endfunction
|
||||
|
||||
" <https://github.com/kana/vim-textobj-indent/blob/deb76867c302f933c8f21753806cbf2d8461b548/autoload/textobj/indent.vim#L120-L127>
|
||||
function dotfiles#indent_motion#indent_level_of(linenr)
|
||||
function! dotfiles#indent_motion#indent_level_of(linenr) abort
|
||||
if getline(a:linenr) ==# ""
|
||||
return -1
|
||||
endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function dotfiles#utils#array_remove_element(array, element)
|
||||
function! dotfiles#utils#array_remove_element(array, element) abort
|
||||
let index = index(a:array, a:element)
|
||||
if index >= 0
|
||||
call remove(a:array, index)
|
||||
|
|
|
@ -13,3 +13,15 @@
|
|||
nnoremap <leader>gp :Git push
|
||||
nnoremap <leader>gP :Git push --force-with-lease
|
||||
" }}}
|
||||
|
||||
" Fugitive.vim handlers {{{
|
||||
|
||||
if !exists('g:fugitive_browse_handlers')
|
||||
let g:fugitive_browse_handlers = []
|
||||
endif
|
||||
|
||||
if index(g:fugitive_browse_handlers, function('dotfiles#fugitive#aur#handler')) < 0
|
||||
call insert(g:fugitive_browse_handlers, function('dotfiles#fugitive#aur#handler'))
|
||||
endif
|
||||
|
||||
" }}}
|
||||
|
|
Loading…
Reference in a new issue