diff --git a/nvim/autoload/dotfiles/fugitive/aur.vim b/nvim/autoload/dotfiles/fugitive/aur.vim new file mode 100644 index 0000000..18df068 --- /dev/null +++ b/nvim/autoload/dotfiles/fugitive/aur.vim @@ -0,0 +1,84 @@ +" Based on +" Also see . +" Other intersting links: +" +" +" +" +" +" +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 +" and . +" Also see . +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 diff --git a/nvim/autoload/dotfiles/indent_motion.vim b/nvim/autoload/dotfiles/indent_motion.vim index 1d58e8c..42ab37d 100644 --- a/nvim/autoload/dotfiles/indent_motion.vim +++ b/nvim/autoload/dotfiles/indent_motion.vim @@ -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 " -function dotfiles#indent_motion#indent_level_of(linenr) +function! dotfiles#indent_motion#indent_level_of(linenr) abort if getline(a:linenr) ==# "" return -1 endif diff --git a/nvim/autoload/dotfiles/utils.vim b/nvim/autoload/dotfiles/utils.vim index adf58cc..b96de6e 100644 --- a/nvim/autoload/dotfiles/utils.vim +++ b/nvim/autoload/dotfiles/utils.vim @@ -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) diff --git a/nvim/plugin/git.vim b/nvim/plugin/git.vim index 1b8b235..54455b3 100644 --- a/nvim/plugin/git.vim +++ b/nvim/plugin/git.vim @@ -13,3 +13,15 @@ nnoremap gp :Git push nnoremap 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 + +" }}} diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 8d960ae..b044eb4 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -107,3 +107,7 @@ if ! command_exists update-grub; then # left as a challenge to the documentation reader. alias update-grub="grub-mkconfig -o /boot/grub/grub.cfg" fi + +if command_exists kitty && ! command_exists icat; then + alias icat="kitty +kitten icat" +fi