From d0fba2c7c6a04c1717a175821848c5edae1eb6a8 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 18 Nov 2016 13:25:12 +0100 Subject: [PATCH] Extend id-manager functionality Add new macros that can fetch the account-id and password for a given account. --- init.el | 1 + lisp/idm.el | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lisp/idm.el diff --git a/init.el b/init.el index 66a6372..f10c27e 100644 --- a/init.el +++ b/init.el @@ -513,6 +513,7 @@ (use-package id-manager :ensure t :config + (load "idm") (setq idm-database-file (expand-file-name "idm-db.gpg" user-emacs-directory)) :bind (:map gpolonkai/pers-map diff --git a/lisp/idm.el b/lisp/idm.el new file mode 100644 index 0000000..aeb31c3 --- /dev/null +++ b/lisp/idm.el @@ -0,0 +1,21 @@ +;; id-manager extensions + +(defun gpolonkai/idm-record-get-field (record field) + "Get FIELD of an id-manager RECORD." + (let ((funcname (intern (concat "idm-record-" (symbol-name field))))) + (when (fboundp funcname) + (funcall funcname record)))) + +(defun gpolonkai/idm-get-field-for-account (account field) + "Get id-manager password for ACCOUNT." + (let ((db (idm-load-db)) + (lookup-record)) + (dolist (record (funcall db 'get-all-records) password) + (when (string= "WikEmacs" (idm-record-name record)) + (setq password (gpolonkai/idm-record-get-field record field)))))) + +(defmacro gpolonkai/idm-get-password-for-account (account) + `(gpolonkai/idm-get-field-for-account ,account 'password)) + +(defmacro gpolonkai/idm-get-id-for-account (account) + `(gpolonkai/idm-get-field-for-account ,account 'account-id))