diff options
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/lisp/fcuny-commands.el | 47 |
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 |