From 7cd0509aca19e834e4b45401f54781ee0cec6eb1 Mon Sep 17 00:00:00 2001
From: tri <tri@thac.loan>
Date: Sun, 5 Oct 2025 11:53:19 +0700
Subject: [PATCH] add vim-fugitive GBrowse handler example

---
 editor-integrations/vim/plugin/khoe.vim | 34 +++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 editor-integrations/vim/plugin/khoe.vim

diff --git a/editor-integrations/vim/plugin/khoe.vim b/editor-integrations/vim/plugin/khoe.vim
new file mode 100644
index 0000000..30eb43f
--- /dev/null
+++ b/editor-integrations/vim/plugin/khoe.vim
@@ -0,0 +1,34 @@
+" Demonstration of how a custom GBrowse handler for khoe might be implemented.
+" Requires vim-fugitive [1].
+"
+" The target domain is currently hardcoded, but it can certainly be made
+" customizable later.
+"
+" [1]: https://github.com/tpope/vim-fugitive
+
+function! KhoeHandler(opts)
+    if a:opts.type != 'blob'
+        return
+    endif
+
+    let l:repo_path = substitute(a:opts.remote, '/\.git$', '', '')
+    let l:repo_name = split(l:repo_path, '/')[-1]
+    let l:object_id = FugitiveExecute('ls-tree', '-r', a:opts.commit, a:opts.path, '--object-only').stdout[0]
+
+    let l:url = 'https://khoe.thac.loan/_/' . l:repo_name . '/objects/' . l:object_id . '/'
+
+    if a:opts.line1
+        let l:url = l:url . '#L' . a:opts.line1
+    endif
+
+    return l:url
+
+endfunction
+
+if !exists('g:fugitive_browse_handlers')
+  let g:fugitive_browse_handlers = []
+endif
+
+if index(g:fugitive_browse_handlers, function('KhoeHandler')) < 0
+  call insert(g:fugitive_browse_handlers, function('KhoeHandler'))
+endif
-- 
2.47.3

