2021-05-21 00:38:18 +03:00
|
|
|
;;; tools/pass/autoload/pass.el -*- lexical-binding: t; -*-
|
2017-06-11 16:41:18 +02:00
|
|
|
|
2018-05-29 17:50:55 +02:00
|
|
|
(defun +pass--copy-username (entry)
|
|
|
|
(if-let* ((user (+pass-get-field entry +pass-user-fields)))
|
|
|
|
(progn (password-store-clear)
|
|
|
|
(message "Copied username to the kill ring.")
|
|
|
|
(kill-new user))
|
|
|
|
(error "Username not found.")))
|
2017-06-11 18:01:03 +02:00
|
|
|
|
2018-05-29 17:50:55 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; API
|
|
|
|
|
2018-06-19 12:00:40 +02:00
|
|
|
;;;###autoload (autoload 'auth-source-pass-parse-entry "auth-source-pass")
|
2017-12-10 15:37:01 -05:00
|
|
|
;;;###autoload
|
2018-05-29 17:50:55 +02:00
|
|
|
(defalias '+pass-get-entry #'auth-source-pass-parse-entry)
|
2017-12-10 15:37:01 -05:00
|
|
|
|
2017-06-12 02:38:16 +02:00
|
|
|
;;;###autoload
|
2018-05-29 17:50:55 +02:00
|
|
|
(defun +pass-get-field (entry fields &optional noerror)
|
|
|
|
"Fetches the value of a field. FIELDS can be a list of string field names or a
|
|
|
|
single one. If a list, the first field found will be returned. Will error out
|
|
|
|
otherwise, unless NOERROR is non-nill."
|
|
|
|
(if-let* ((data (if (listp entry) entry (+pass-get-entry entry))))
|
2017-12-10 15:37:01 -05:00
|
|
|
(cl-loop for key in (doom-enlist fields)
|
|
|
|
when (assoc key data)
|
|
|
|
return (cdr it))
|
2018-05-29 17:50:55 +02:00
|
|
|
(unless noerror
|
|
|
|
(error "Couldn't find entry: %s" entry))))
|
2017-06-12 02:38:16 +02:00
|
|
|
|
2017-06-12 02:43:35 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +pass-get-user (entry)
|
2018-05-29 17:50:55 +02:00
|
|
|
"Fetches the user field from ENTRY. Each of `+pass-user-fields' are tried in
|
|
|
|
search of your username. May prompt for your gpg passphrase."
|
2017-06-12 02:43:35 +02:00
|
|
|
(+pass-get-field entry +pass-user-fields))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +pass-get-secret (entry)
|
2018-05-29 17:50:55 +02:00
|
|
|
"Fetches your secret from ENTRY. May prompt for your gpg passphrase."
|
2017-06-14 21:03:20 +02:00
|
|
|
(+pass-get-field entry 'secret))
|
2017-06-12 02:43:35 +02:00
|
|
|
|
2017-06-12 02:38:16 +02:00
|
|
|
|
2018-05-29 17:50:55 +02:00
|
|
|
;;
|
|
|
|
;; Commands
|
2017-06-12 02:38:16 +02:00
|
|
|
|
2018-06-23 01:55:52 +02:00
|
|
|
;;;###autoload (autoload 'password-store-dir "password-store")
|
2018-06-19 12:00:40 +02:00
|
|
|
;;;###autoload (autoload 'password-store-list "password-store")
|
|
|
|
;;;###autoload (autoload 'password-store--completing-read "password-store")
|
2018-05-29 17:50:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-10-02 00:05:43 +02:00
|
|
|
(define-obsolete-function-alias '+pass/edit-entry #'password-store-edit "21.12")
|
2018-05-29 17:50:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-10-02 00:05:43 +02:00
|
|
|
(define-obsolete-function-alias '+pass/copy-field #'password-store-copy-field "21.12")
|
2018-05-29 17:50:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-10-02 00:05:43 +02:00
|
|
|
(define-obsolete-function-alias '+pass/copy-secret #'password-store-copy "21.12")
|
2018-05-29 17:50:55 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +pass/copy-user (entry)
|
|
|
|
"Interactively search for an entry and copy the login to your clipboard. The
|
|
|
|
fields in `+pass-user-fields' is used to find the login field."
|
|
|
|
(interactive
|
|
|
|
(list (password-store--completing-read)))
|
|
|
|
(+pass--copy-username entry))
|
2017-06-11 16:41:18 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-10-02 00:05:43 +02:00
|
|
|
(define-obsolete-function-alias '+pass/browse-url #'password-store-url "21.12")
|