From a496ef9734dfd6d1e29f492659985512ab6723b2 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 19 Aug 2022 20:34:10 +0200 Subject: [PATCH] Add function to retrieve password from Org item by ID This function is experimental and may need to be extended to search for IDs in a specific password file that are is not necessarily a member of `org-agenda-files`. --- init.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/init.el b/init.el index f3500d4..4b0d7c5 100644 --- a/init.el +++ b/init.el @@ -1917,6 +1917,32 @@ respectively." :init (setq epg-debug t epg-gpg-program "gpg")) +(use-package org-password-manager + :commands (org-password-manager-get-password-by-id) + :config (progn + + (defun org-password-manager-get-password-by-id (id) + "Retrieve password from Org item identified by ID. + +The password is assumed to be stored at the PASSWORD property." + + (let ((pom (org-id-find id 'marker))) + (unless (markerp pom) + (user-error "Cannot find item with id %s" id)) + + (let ((heading (org-entry-get pom "ITEM")) + (pw (org-entry-get pom "PASSWORD"))) + (when (null pw) + (user-error "PASSWORD property not set for ā€œ%sā€" heading)) + + (funcall interprogram-cut-function pw) + (run-at-time org-password-manager-default-password-wait-time + nil + (lambda () (funcall interprogram-cut-function ""))) + (message "Password for ā€œ%sā€ securly copied to system clipboard; will be overwritten in %s." + heading + org-password-manager-default-password-wait-time)))))) + ;; * Appearance