aboutsummaryrefslogtreecommitdiff
path: root/content/blog/git-link-and-sourcegraph.md
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-07-04 11:36:33 -0700
committerFranck Cuny <franck@fcuny.net>2024-07-04 11:36:33 -0700
commitfccd15aec3507fd3f0cb4a2c18a0ec1af1d69c1f (patch)
treef506115024e7e6247279409fa053e59927ec398c /content/blog/git-link-and-sourcegraph.md
parentdont format html files with prettier (diff)
downloadfcuny.net-fccd15aec3507fd3f0cb4a2c18a0ec1af1d69c1f.tar.gz
migrate to zola
Diffstat (limited to '')
-rw-r--r--content/blog/git-link-and-sourcegraph.md56
1 files changed, 29 insertions, 27 deletions
diff --git a/content/blog/git-link-and-sourcegraph.md b/content/blog/git-link-and-sourcegraph.md
index affbe8b..073068d 100644
--- a/content/blog/git-link-and-sourcegraph.md
+++ b/content/blog/git-link-and-sourcegraph.md
@@ -13,33 +13,35 @@ git remote add sourcegraph https://sourcegraph.com/github.com/sshaw/copy-as-form
The next time you run `M-x git-link` in a buffer, it will use the URL associated with that remote. That's works great, except that now you need to add this for every repository. Instead, for my usage, I came up with the following solution:
- (use-package git-link
- :ensure t
- :after magit
- :bind (("C-c g l" . git-link)
- ("C-c g a" . git-link-commit))
- :config
- (defun fcuny/get-sg-remote-from-hostname (hostname)
- (format "sourcegraph.<$domain>.<$tld>/%s" hostname))
-
- (defun fcuny/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
- ;;; For a given repository, build the proper link for sourcegraph.
- ;;; Use the default branch of the repository instead of the
- ;;; current one (we might be on a feature branch that is not
- ;;; available on the remote).
- (require 'magit-branch)
- (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname))
- (main-branch (magit-main-branch)))
- (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
-
- (defun fcuny/git-link-commit-work-sourcegraph (hostname dirname commit)
- (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname)))
- (git-link-commit-sourcegraph sg-base-url dirname commit)))
-
- (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))
-
- (setq git-link-open-in-browser 't))
+```lisp
+(use-package git-link
+ :ensure t
+ :after magit
+ :bind (("C-c g l" . git-link)
+ ("C-c g a" . git-link-commit))
+ :config
+ (defun fcuny/get-sg-remote-from-hostname (hostname)
+ (format "sourcegraph.<$domain>.<$tld>/%s" hostname))
+
+ (defun fcuny/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
+ ;;; For a given repository, build the proper link for sourcegraph.
+ ;;; Use the default branch of the repository instead of the
+ ;;; current one (we might be on a feature branch that is not
+ ;;; available on the remote).
+ (require 'magit-branch)
+ (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname))
+ (main-branch (magit-main-branch)))
+ (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
+
+ (defun fcuny/git-link-commit-work-sourcegraph (hostname dirname commit)
+ (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname)))
+ (git-link-commit-sourcegraph sg-base-url dirname commit)))
+
+ (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))
+
+ (setq git-link-open-in-browser 't))
+```
We use different domains to host various git repositories at work (e.g. `git.$work`, `gitfoo.$work`, etc). Each of them map to a different URI for sourcegraph (e.g. `sourcegraph.$work/gitfoo`).