From c3cd4201fcfbca8c135bd4fae9c9f616cbd961e6 Mon Sep 17 00:00:00 2001 From: Lucas Sta Maria Date: Sun, 6 Aug 2023 22:20:40 -0700 Subject: [PATCH] feat: add `gpg-encrypt-sign-save-buffer` function Signed-off-by: Lucas Sta Maria --- .emacs.d/include/gpgconfig.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.emacs.d/include/gpgconfig.el b/.emacs.d/include/gpgconfig.el index f7719af..a6d5472 100644 --- a/.emacs.d/include/gpgconfig.el +++ b/.emacs.d/include/gpgconfig.el @@ -49,5 +49,26 @@ (setq info (-filter (lambda (s) (not (string-match "image" (car s)))) info)) info))) +(defun gpg-encrypt-sign-save-buffer (&optional filename) + "Encrypt, sign, and save the buffer as FILENAME.asc for the recipients." + (interactive) + + (let* ((key-alist (gpg-public-keys)) + (recipients (completing-read-multiple "Recipients: " key-alist)) + (recipient-keys (mapcar (lambda (x) (cdr (assoc x key-alist))) + recipients)) + (recipients-cli-args (mapconcat (lambda (s) (concat "-r " s)) + recipient-keys + " "))) + (unless (or filename buffer-file-name) + (setq filename (read-string "Filename: " nil nil))) + (let ((gpg-encrypt-command + (concat "gpg --encrypt --sign --armor " + recipients-cli-args + " " + (or filename buffer-file-name)))) + (redraw-display) + (term gpg-encrypt-command)))) + (provide 'gpgconfig) ;;; gpgconfig.el ends here