From b35cd48cd4051a0d7f41aaae15b53208a8caf66a Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Thu, 9 Jan 2020 15:01:13 +0100 Subject: Add a function to create action stamp from Magit buffer --- .emacs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.emacs b/.emacs index e813ab6..35fd2e9 100644 --- a/.emacs +++ b/.emacs @@ -195,6 +195,25 @@ ;; in stone, and I would miss out on future updates by Magit. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell) +(defun my/action-stamp-at-point () + (interactive) + (when-let ((rev (cond + ;; TODO: add vc support. + ((derived-mode-p 'magit-mode) + (magit-branch-or-commit-at-point))))) + (let* ((cmd "git show --no-patch --date=unix --format='%ad!%ae'") + (git-info (shell-command-to-string (format "%s %s" cmd rev)))) + (pcase git-info + ((rx (let timestamp-str (+ digit)) + "!" + (let mail (+ anychar)) + "\n") + (let* ((timestamp (string-to-number timestamp-str)) + (date (format-time-string "%FT%TZ" timestamp t)) + (action-stamp (format "%s!%s" date mail))) + (kill-new action-stamp) + (message action-stamp))))))) + ;; rg re-binds C-n and C-p. I loathe arrow keys for regular movement, ;; and n and p are laggy because they visit the matched files. ;; Since I can't blame anyone for telling me "It's 2019; use the arrow -- cgit v1.2.3