summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--emacs/custom/fcuny-git.el44
1 files changed, 26 insertions, 18 deletions
diff --git a/emacs/custom/fcuny-git.el b/emacs/custom/fcuny-git.el
index 340da9c..b85a9ea 100644
--- a/emacs/custom/fcuny-git.el
+++ b/emacs/custom/fcuny-git.el
@@ -84,34 +84,42 @@
   :config
   (add-to-list 'forge-alist '("git.fcuny.net:222" "git.fcuny.net/api/v1" "git.fcuny.net" forge-gitea-repository)))
 
-;; 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
+  :bind (("C-c g l" . git-link)
+         ("C-c g a" . git-link-commit))
   :config
-  (defun git-link-sourcegraph (hostname dirname filename _branch commit start end)
-    (let ((line-or-range (if end (format "%s-%s" start end) start)))
+  (defvar fcuny/map-git-remote-to-sg
+    '(("git.twitter.biz" "sourcegraph.twitter.biz/twitter.biz")
+      ("gitpuppet.twitter.biz" "sourcegraph.twitter.biz/gitpuppet.twitter.biz")))
+
+  (defun fcuny/get-sg-remote-from-hostname (hostname)
+    (nth 1 (assoc hostname fcuny/map-git-remote-to-sg)))
+
+  (defun fcuny/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
+    (let ((line-or-range (if end (format "%s-%s" start end) start))
+          (sg-base-url (fcuny/get-sg-remote-from-hostname hostname)))
       (format "https://%s/%s@%s/-/blob/%s#L%s"
-              hostname
+              sg-base-url
               dirname
               commit
               filename
               line-or-range)))
 
-  (defun git-link-commit-sourcegraph (hostname dirname commit)
-    (format "https://%s/%s/-/commit/%s"
-            hostname
-            dirname
-            commit))
+  (defun fcuny/git-link-commit-work-sourcegraph (hostname dirname commit)
+    (let (sg-base-url (fcuny/get-sg-remote-from-hostname hostname))
+      (format "https://%s/%s/-/commit/%s"
+              sg-base-url
+              dirname
+              commit)))
+
+  ;; for work related repositories, open them in our instance of sourcegraph
+  (add-to-list 'git-link-remote-alist '("twitter" fcuny/git-link-work-sourcegraph))
+  (add-to-list 'git-link-commit-remote-alist '("twitter" fcuny/git-link-commit-work-sourcegraph))
 
-  (add-to-list 'git-link-remote-alist '("sourcegraph" git-link-sourcegraph))
-  (add-to-list 'git-link-commit-remote-alist '("sourcegraph" git-link-commit-sourcegraph))
+  ;; for personal code I use gitea, which is similar to codeberg
+  (add-to-list 'git-link-remote-alist '("git\\.fcuny\\.net" git-link-codeberg))
+  (add-to-list 'git-link-commit-remote-alist '("git\\.fcuny\\.net" git-link-commit-codeberg))
 
   (setq git-link-open-in-browser 't))