Last active
November 21, 2022 21:55
-
-
Save jiito/afb4911bd518bb1c9c8ab6ae0e534828 to your computer and use it in GitHub Desktop.
Get the branch identifier in lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; git.el -*- lexical-binding: t; -*- | |
(defun get-jira-prefix (iden) | |
"Get the JIRA branch identifier from IDEN." | |
(let ((prefix (string-match "[A-Za-z]+-[0-9]+" iden))) | |
(if (not prefix) | |
(message iden) (substring iden prefix (match-end 0)) | |
) | |
) | |
) | |
(defun current-git-branch () | |
"Get the current git branch." | |
(vc-git--symbolic-ref (buffer-file-name))) | |
(defun insert-branch-id() | |
"Insert the ticket identifier at point" | |
(insert (format "[%s]: " (get-jira-prefix (current-git-branch)) )) | |
(evil-insert-state) | |
) | |
;; add to commit with magit | |
(add-hook 'git-commit-setup-hook 'insert-branch-id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment