summary refs log tree commit diff
path: root/emacs.d/custom
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--emacs.d/custom/fcuny-git.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/emacs.d/custom/fcuny-git.el b/emacs.d/custom/fcuny-git.el
index 48409a7..e3b8c45 100644
--- a/emacs.d/custom/fcuny-git.el
+++ b/emacs.d/custom/fcuny-git.el
@@ -28,6 +28,37 @@
     (setq-local fill-column 72)
     (setq-local comment-auto-fill-only-comments nil)))
 
+;; from https://sideshowcoder.com/2020/07/02/opening-sourcegraph-from-emacs/
+;; in a repo, add the following in .git/config:
+;;
+;; [git-link]
+;;        remote = mysourcegraph.sourcegraph
+;; [remote "mysourcegraph.sourcegraph"]
+;;        url = https://sourcegraph.twitter.biz/gitpuppet.twitter.biz/puppet-twitter
+;;
+(use-package git-link
+  :ensure t
+  :config
+  (defun git-link-sourcegraph (hostname dirname filename _branch commit start end)
+    (let ((line-or-range (if end (format "%s-%s" start end) start)))
+      (format "https://%s/%s@%s/-/blob/%s#L%s"
+              hostname
+              dirname
+              commit
+              filename
+              line-or-range)))
+
+  (defun git-link-commit-sourcegraph (hostname dirname commit)
+    (format "https://%s/%s/-/commit/%s"
+            hostname
+            dirname
+            commit))
+
+  (add-to-list 'git-link-remote-alist '("sourcegraph" git-link-sourcegraph))
+  (add-to-list 'git-link-commit-remote-alist '("sourcegraph" git-link-commit-sourcegraph))
+
+  (setq git-link-open-in-browser 't))
+
 ;; https://magit.vc/manual/magit/Per_002dRepository-Configuration.html
 ;; we don't want to refresh buffers in source. This should help with
 ;; performances.