commit eb30b33e5cc94150b809c39d2dcda8b7b8027090 parent 04ecafee8508888065065705e037ccb842d79b1a Author: andsy10 <andsy1016@gmail.com> Date: Fri, 7 Aug 2026 16:27:39 +0800 Add metadata field appending functions for pass Diffstat:
| M | lisp/init-package.el | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++-- |
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/lisp/init-package.el b/lisp/init-package.el @@ -210,13 +210,58 @@ _a_ : all dwim :hook (syncthing-mode . disable-truncate-lines)) -;; pass +;; pinentry (if *is-linux* (use-package pinentry :hook (after-init . pinentry-start))) -(use-package pass) +;; pass +(use-package pass + :config + (defvar my-pass-meta-fields '("url" "username" "email") + "List of pass metadata fileds for completion.") + + (defun my-password-store-append-field (entry field value) + "Append metadata to ENTRY." + (interactive + (let* ((entry (password-store--completing-read t)) + (field (completing-read "Field: " my-pass-meta-fields)) + (value (read-string (format "%s: " field)))) + (list entry field value))) + (let* ((old (string-trim-right (password-store--run-show entry))) + (new (format "%s\n%s: %s" old field value)) + (code (process-file-shell-command + (format "printf '%%s' %s | %s insert --multiline --force %s" + (shell-quote-argument new) + password-store-executable + (shell-quote-argument entry))))) + (unless (zerop code) (user-error "Update %s failed" entry)) + (message "Add %s: %s → %s" field value entry))) + + (defun my-pass-append-field () + "Append metadata to the entry at point." + (interactive) + (pass--with-closest-entry + entry + (call-interactively + (lambda (field value) + (interactive + (let* ((f (completing-read "Field: " my-pass-meta-fields)) + (v (read-string (format "%s: " f) + (when (equal f "url") (current-kill 0 t))))) + (list f v))) + (my-password-store-append-field entry field value))))) + + (defun my-pass-copy-email () + "Copy email of entry at piont to kill ring." + (interactive) + (pass-copy-field "email")) + + (general-def pass-mode-map + "a" #'my-pass-append-field + "E" #'pass-edit + "e" #'my-pass-copy-email)) ;; elfeed (use-package elfeed