summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-03-22 08:02:54 -0700
committerFranck Cuny <franck@fcuny.net>2022-03-22 08:02:54 -0700
commita1af54844fb82898e1da2b1a75baf58389ad1bf2 (patch)
tree3b2680ec50cc5ec1be8e2bcaf6af50a8be83e29c
parentwork: manage work related functions (diff)
downloademacs.d-a1af54844fb82898e1da2b1a75baf58389ad1bf2.tar.gz
commands: start refactoring
-rw-r--r--emacs/lisp/fcuny-commands.el47
1 files changed, 46 insertions, 1 deletions
diff --git a/emacs/lisp/fcuny-commands.el b/emacs/lisp/fcuny-commands.el
index a286e9f..842fb3e 100644
--- a/emacs/lisp/fcuny-commands.el
+++ b/emacs/lisp/fcuny-commands.el
@@ -1,3 +1,13 @@
+;;; fcuny-commands -- my functions
+
+;;; Commentary:
+;;; Code:
+
+(require 'fcuny-vars)
+(require 'magit)
+(require 'magit-branch)
+(require 'git-link)
+
 (defun rename-this-buffer-and-file ()
   "Renames current buffer and file it is visiting."
   (interactive)
@@ -17,11 +27,46 @@
                (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
 
 (defun uniquify-region-lines (beg end)
-  "Remove duplicate adjacent lines in region."
+  "Remove duplicate adjacent lines in region between BEG and END."
   (interactive "*r")
   (save-excursion
     (goto-char beg)
     (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
       (replace-match "\\1"))))
 
+(defun fcuny/clone-repo (url)
+  "Clone a repository in the workspace using URL."
+  (interactive "sURL:")
+  (let* ((repo-name (magit-clone--url-to-name url))
+         (target-dir (concat fcuny/path-workspace "/" repo-name)))
+    (magit-clone-regular url target-dir nil)))
+
+(defun fcuny/get-sg-remote-from-hostname (hostname)
+  "Create a sourcegraph URL from HOSTNAME."
+  (format "sourcegraph.rbx.com/%s" hostname))
+
+(defun fcuny/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
+  "Create the link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END."
+  ;; 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).
+  (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)
+  "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT."
+  (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname)))
+    (git-link-commit-sourcegraph sg-base-url dirname commit)))
+
+;; for work related repositories, open them in our instance of sourcegraph
+(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" fcuny/git-link-work-sourcegraph))
+(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" fcuny/git-link-commit-work-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))
+
 (provide 'fcuny-commands)
+
+;;; fcuny-commands.el ends here