size: 1 KiB

1" Demonstration of how a custom GBrowse handler for khoe might be implemented.
2" Requires vim-fugitive [1].
3"
4" The target domain is currently hardcoded, but it can certainly be made
5" customizable later.
6"
7" [1]: https://github.com/tpope/vim-fugitive
8
9function! KhoeHandler(opts)
10 if a:opts.type != 'blob'
11 return
12 endif
13
14 let l:repo_path = substitute(a:opts.remote, '/\.git$', '', '')
15 let l:repo_name = split(l:repo_path, '/')[-1]
16 let l:object_id = FugitiveExecute('ls-tree', '-r', a:opts.commit, a:opts.path, '--object-only').stdout[0]
17
18 let l:url = 'https://khoe.thac.loan/_/' . l:repo_name . '/objects/' . l:object_id . '/'
19
20 if a:opts.line1
21 let l:url = l:url . '#L' . a:opts.line1
22 if a:opts.line2
23 let l:url = l:url . '-' . a:opts.line2
24 endif
25 endif
26
27 return l:url
28
29endfunction
30
31if !exists('g:fugitive_browse_handlers')
32 let g:fugitive_browse_handlers = []
33endif
34
35if index(g:fugitive_browse_handlers, function('KhoeHandler')) < 0
36 call insert(g:fugitive_browse_handlers, function('KhoeHandler'))
37endif