From 7272fa4fa55bf83d238aef2b378933a8854c3d5c Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Fri, 6 Sep 2024 23:19:38 +0300 Subject: [PATCH] password-store-ivy -> password-store-completion --- README.org | 78 ++++++---- password-store-completion.el | 291 +++++++++++++++++++++++++++++++++++ password-store-embark.el | 54 +++++++ password-store-ivy.el | 281 +++------------------------------ 4 files changed, 413 insertions(+), 291 deletions(-) create mode 100644 password-store-completion.el create mode 100644 password-store-embark.el diff --git a/README.org b/README.org index 9a761f4..fea26e3 100644 --- a/README.org +++ b/README.org @@ -1,51 +1,63 @@ -#+TITLE: password-store-ivy +#+TITLE: password-store-completion -A [[https://www.passwordstore.org/][pass]] frontend based on [[https://github.com/abo-abo/swiper#ivy][Ivy]], made primarily to use with [[https://github.com/ch11ng/exwm][EXWM]] and [[https://github.com/tumashu/ivy-posframe][ivy-posframe]]. Types fields from entries. +A completion-based pass frontend inspired by [[https://github.com/carnager/rofi-pass][rofi-pass]]. Integrates with [[https://github.com/abo-abo/swiper][Ivy]] or [[https://github.com/oantolin/embark][Embark]]. -Also take a look at Nicolas Petton's [[https://github.com/NicolasPetton/pass][pass]], =password-store-ivy= is designed as complementary to the Nicolas' package. +The main purpose is typing passwords with =xdotool= (useful in [[https://github.com/emacs-exwm/exwm][EXWM]]). -This package is made with Ivy because I need some fine-tuning like actions and turning off sorting in some completions, and Ivy happens to be the completion system I'm using now. +Also take a look at Nicolas Petton's [[https://github.com/NicolasPetton/pass][pass]]. =password-store-completion= is designed as complementary to Nicolas' package. * Installation -As the package isn’t yet available anywhere but in this repository, you can clone the repository, add it to the load-path and require the package. My preferred way is =use-package= with =straight=: +As the package isn't yet available anywhere but in this repository, you can clone the repository, add it to the load-path, and require the package. My preferred way is =use-package= with =straight=: #+begin_src emacs-lisp -(use-package password-store-ivy - :straight (:host github :repo "SqrtMinusOne/password-store-ivy") - :after (exwm)) +(use-package password-store-completion + :straight (:host github :repo "SqrtMinusOne/password-store-completion")) +#+end_src + +=xdotool= has to be available in =$PATH=. + +For Ivy integration: +#+begin_src emacs-lisp +(require 'password-store-ivy) +#+end_src +Also be sure to load the main package before Ivy. + +For Embark integration: +#+begin_src emacs-lisp +(require 'password-store-embark) +(password-store-embark-mode) #+end_src -This package types stuff with =xdotool=, so you need to have that available in your =$PATH=. * Usage Emacs' built-in [[https://www.gnu.org/software/emacs/manual/html_node/auth/The-Unix-password-store.html][password store]] integration has to be set up. -The only command is =M-x password-store-ivy=, which invokes Ivy to select an entry from the pass database. Available commands in the selection buffer: -- =M-a=. Perform autotype -- =M-p=. Type password -- =M-u=. Type username -- =M-U=. Type url -- =M-f=. Select a field to type +For Ivy integration, the command is =M-x password-store-ivy=, which invokes Ivy to select an entry from the pass database. Available commands in the selection buffer: +- =M-a=: Perform autotype +- =M-p=: Type password +- =M-u=: Type username +- =M-U=: Type URL +- =M-f=: Select a field to type + +For other completion frameworks, run =M-x password-store-completion=. If Embark integration is enabled, the same actions are added. * Customization -There are a few parameters that control delays: -- =password-store-ivy-initial-wait= controls the initial delay before starting to type a sequence (in milliseconds) -- =password-store-ivy-delay= controls the delay between typing characters (in milliseconds) +The following parameters control delays: +- =password-store-completion-initial-wait= controls the initial delay before starting to type a sequence (in milliseconds) +- =password-store-completion-delay= controls the delay between typing characters (in milliseconds) -There is also =password-store-ivy-sequences= that determines the sequence of actions =password-store-ivy= performs. - -It is an alist with the following required keys (corresponding to the basic actions): +=password-store-completion-sequences= determines the steps of sequences. It is an alist; the keys correspond to the default sequences: - =autotype= - =password= - =username= - =url= The values are lists of the following elements: -- =wait=. Wait for =password-store-ivy-initial-wait= milliseconds -- =(wait )=. Wait for ==. -- =(key )=. Type ==. -- =(field )=. Type == of entry. +- =wait=: Wait for =password-store-completion-initial-wait= milliseconds +- =(wait )=: Wait for == +- =(key )=: Type == +- =(field )=: Type == of entry -For example, the starting values: +The default value is as follows: #+begin_src emacs-lisp '((autotype . (wait (field . "username") @@ -57,12 +69,22 @@ For example, the starting values: (url . (wait (field . "url")))) #+end_src -In addition to the global override, sequences can be overriden per-entry with a field called =sequence-=, where == is a key of =password-store-ivy-sequences=. +Sequences can also be overridden in a particular entry with a field called =sequence-=, where == is a key of =password-store-completion-sequences=. -For example, here is an override to press =Tab= twice: +For example, to press =Tab= twice in the =autotype= sequence: #+begin_example username: thexcloud@gmail.com url: sequence-autotype: (wait (field . "username") (key . "Tab") (key . "Tab") (field . secret) (key . "Return")) #+end_example + +Or, create a custom sequence: +#+begin_example + +username: thexcloud@gmail.com +url: +sequence-doubletab: (wait (field . "username") (key . "Tab") (key . "Tab") (field . secret) (key . "Return")) +#+end_example + +Custom sequences can be run in the field selection interface (=M-f= in Ivy, =M-x embark-act f= in Embark). diff --git a/password-store-completion.el b/password-store-completion.el new file mode 100644 index 0000000..32aca0c --- /dev/null +++ b/password-store-completion.el @@ -0,0 +1,291 @@ +;;; password-store-completion.el --- A completion-based pass frontend -*- lexical-binding: t -*- + +;; Copyright (C) 2022-2024 Korytov Pavel + +;; Author: Korytov Pavel +;; Maintainer: Korytov Pavel +;; Version: 0.2.0 +;; Package-Requires: ((emacs "27.1") (password-store "2.1.4")) +;; Homepage: https://github.com/SqrtMinusOne/password-store-completion +;; Published-At: 2022-02-13 + +;; This file is NOT part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; A completion-based pass frontend. Integrates with Ivy or Embark. +;; +;; This package types stuff with xdotool, so you need to have that +;; available in your $PATH. +;; +;; To enable Ivy integration, run: +;; \\=(require \\='password-store-ivy) +;; +;; To enable Embark integration, run: +;; \\=(require \\='password-store-embark) +;; \\=(password-store-embark-mode) +;; +;; The available commands are `password-store-ivy' for Ivy and +;; `password-store-completion' for the remaining completion +;; frameworks. +;; +;; Also take a look at the package README at +;; . + +;;; Code: + +(require 'seq) +(require 'auth-source-pass) +(require 'password-store) + +(defgroup password-store-completion () + "A completion-based pass frontend." + :group 'password-store) + +(defcustom password-store-completion-initial-wait 250 + "How many milliseconds to wait before typing characters." + :type 'integer + :group 'password-store-completion) + +(defcustom password-store-completion-delay 50 + "Delay between typing characters." + :type 'integer + :group 'password-store-completion) + +(defcustom password-store-completion-sequences + '((autotype . (wait + (field . "username") + (key . "Tab") + (field . secret) + (key . "Return"))) + (password . (wait (field . secret))) + (username . (wait (field . "username"))) + (url . (wait (field . "url")))) + "Sequences to execute by `password-store-completion'. + +It is an alist with the following required keys (corresponding to the +basic actions): +- autotype +- password +- username +- url +Values are lists of symbols that determine action. + +Take a look at `password-store-completion--get-commands' for available +options." + :group 'password-store-completion + :options '(autotype password username url) + :type '(alist :key-type (symbol :tag "Sequence name") + :value-type + (repeat :tag "Sequence contents" + (choice (const :tag "Wait for `password-store-completion-initial-wait'" wait) + (cons :tag "Wait for milliseconds" + (const :tag "Wait for milliseconds" wait) + (integer :tag "Number of milliseconds to wait")) + (cons :tag "Enter a field" + (const :tag "Enter a field" field) + (choice (const :tag "Password" secret) + (const :tag "Username" "username") + (const :tag "URL" "url") + (string :tag "Other field"))) + (cons :tag "Press a key" + (const :tag "Press a key" key) + (choice (const "Tab") + (const "Return") + (string :tag "Other key"))))))) + +(defcustom password-store-completion-end-message "Finished typing" + "A message to show after typing is finished." + :type '(choice (const :tag "No message" nil) + (string :tag "Message")) + :group 'password-store-completion) + +(defun password-store-completion--async-command (command callback) + "Run COMMAND in shell asynchronously. + +Call CALLBACK when the command is finished." + (let* ((proc (start-process "pass" nil shell-file-name "-c" command))) + (set-process-sentinel + proc + (lambda (process _msg) + (pcase (process-status process) + ('exit (funcall callback)) + ('fatal (error "Error in running %s" command))))))) + +(defun password-store-completion--async-commands (commands &optional callback) + "Run COMMANDS asynchronously. + +Call CALLBACK when the last command is executed." + (if (seq-empty-p commands) + (progn + (when callback + (funcall callback)) + (when password-store-completion-end-message + (message password-store-completion-end-message))) + (password-store-completion--async-command + (car commands) + (lambda () + (password-store-completion--async-commands (cdr commands) callback))))) + +(defun password-store-completion--get-type-command (str) + "Return a command to type STR." + (concat "printf " (shell-quote-argument str) + "| xdotool type --clearmodifiers --file - --delay " + (number-to-string password-store-completion-delay))) + +(defun password-store-completion--get-wait-command (&optional milliseconds) + "Return a command to sleep for MILLISECONDS. + +If MILLISECONDS is nil, default to `password-store-completion-initial-wait'." + (format "sleep %f" + (/ (float (or milliseconds password-store-completion-initial-wait)) + 1000))) + +(defun password-store-completion--get-key-command (key) + "Get a command that presses KEY." + (format "xdotool key %s" key)) + +(defun password-store-completion--get-entry-command (entry field) + "Get a command to type FIELD of ENTRY. + +ENTRY is an alist, FIELD is a symbol or string that can be a key of alist." + (when-let ((contents (alist-get field entry nil nil #'equal))) + (password-store-completion--get-type-command contents))) + +(defun password-store-completion--get-commands (entry sequence) + "Get a list of commands to execute for ENTRY. + +SEQUENCE is a list of the following elements: +- `wait'. Wait for `password-store-completion-initial-wait' milliseconds. +- `(wait )'. Wait for . +- `(key )'. Type . +- `(field )'. Type of entry." + (seq-filter + (lambda (command) (not (seq-empty-p command))) + (mapcar + (lambda (elem) + (unless (sequencep elem) + (setq elem (list elem))) + (pcase (car elem) + ('wait (password-store-completion--get-wait-command (cdr elem))) + ('key (password-store-completion--get-key-command (cdr elem))) + ('field (password-store-completion--get-entry-command entry (cdr elem))) + (_ (error "Wrong field: %s" (prin1-to-string elem))))) + sequence))) + +(defun password-store-completion--get-entry (entry-name) + "Get a pass entry by ENTRY-NAME." + (let ((entry (auth-source-pass-parse-entry entry-name))) + (unless entry + (user-error "The entry is empty. Perhaps the password was incorrect?")) + entry)) + +(defun password-store-completion--get-sequence (entry sequence-name) + "Get a sequence from an ENTRY. +SEQUENCE-NAME is a key of `password-store-completion-sequences'." + (or (when-let ((str (alist-get (format "sequence-%s" (symbol-name sequence-name)) + entry nil nil #'equal))) + (condition-case err + (car (read-from-string str)) + (error (error "Error in %s: %s" str (prin1-to-string err))))) + (alist-get sequence-name password-store-completion-sequences))) + +(defmacro password-store-completion--def-command (name &rest body) + "Create functions to be invoked from `password-store-completion'. + +NAME is the base name. The first function created, NAME-command, +can be executed inside the `password-store-completion' completion interface. +The second function, NAME-action, can be registered as an action, +e.g. with `ivy-set-actions'. + +BODY is put inside both functions, wrapped in the code that makes +the current entry available via the `entry' variable." + (declare (indent 1)) + `(progn + ,(when (fboundp #'ivy-exit-with-action) + `(defun ,(intern (format "%s-command" name)) () + (interactive) + (ivy-exit-with-action + (lambda (entry-name) + (let ((entry (password-store-completion--get-entry entry-name))) + ,@body))))) + (defun ,(intern (format "%s-action" name)) (entry-name) + (interactive (list (password-store-completion--read))) + (let ((entry (password-store-completion--get-entry entry-name))) + ,@body)))) + +(password-store-completion--def-command password-store-completion--autotype + (password-store-completion--async-commands + (password-store-completion--get-commands + entry + (password-store-completion--get-sequence entry 'autotype)))) + +(password-store-completion--def-command password-store-completion--password + (password-store-completion--async-commands + (password-store-completion--get-commands + entry + (password-store-completion--get-sequence entry 'password)))) + +(password-store-completion--def-command password-store-completion--username + (password-store-completion--async-commands + (password-store-completion--get-commands + entry + (password-store-completion--get-sequence entry 'username)))) + +(password-store-completion--def-command password-store-completion--url + (password-store-completion--async-commands + (password-store-completion--get-commands + entry + (password-store-completion--get-sequence entry 'url)))) + +(password-store-completion--def-command password-store-completion--fields + (let* ((sequences (mapcar + (lambda (item) + (let ((field-name (car item))) + (when (symbolp field-name) + (setq field-name (symbol-name field-name))) + (if (string-match (rx bos "sequence-") field-name) + `(,field-name . ,(condition-case err + (car (read-from-string (cdr item))) + (error (user-error "Error in %s: %s" + field-name + (prin1-to-string err))))) + `(,field-name . (wait (field . ,(car item))))))) + entry)) + (data (completing-read "Field:" sequences))) + (password-store-completion--async-commands + (password-store-completion--get-commands + entry + (alist-get data sequences nil nil #'equal))))) + +(defun password-store-completion--read () + "Read a pass entry name from minibuffer." + (let ((candidates (password-store-list))) + (completing-read "Pass entry: " + (lambda (string predicate action) + (pcase action + ('metadata '(metadata (category . password-store-pass))) + (_ (all-completions string candidates predicate))))))) + +;;;###autoload +(defun password-store-completion () + "A frontend for pass." + (interactive) + (password-store-completion--password-action + (password-store-completion--read))) + +(provide 'password-store-completion) +;;; password-store-completion.el ends here diff --git a/password-store-embark.el b/password-store-embark.el new file mode 100644 index 0000000..b8f5bdd --- /dev/null +++ b/password-store-embark.el @@ -0,0 +1,54 @@ +;;; password-store-embark.el --- Integrate password-store-completion with Embark -*- lexical-binding: t -*- + +;; Copyright (C) 2022-2024 Korytov Pavel + +;; Author: Korytov Pavel +;; Maintainer: Korytov Pavel + +;; This file is NOT part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Integrate `password-store-completion' with Embark. + +;;; Code: +(require 'embark) +(require 'password-store-completion) + +(defvar password-store-embark-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map embark-general-map) + (define-key map (kbd "p") #'password-store-completion--password-action) + (define-key map (kbd "a") #'password-store-completion--autotype-action) + (define-key map (kbd "f") #'password-store-completion--fields-action) + (define-key map (kbd "u") #'password-store-completion--username-action) + (define-key map (kbd "U") #'password-store-completion--url-action) + map)) + +;;;###autoload +(define-minor-mode password-store-embark-mode + "Toggle integration between `password-store-completion' and Embark." + :group 'password-store-completion + :global t + :init-value nil + (if password-store-embark-mode + (progn + (setf (alist-get 'password-store-pass embark-keymap-alist) + 'password-store-embark-map)) + (setf (alist-get 'password-store-pass embark-keymap-alist) nil))) + +(provide 'password-store-embark) +;;; password-store-embark.el ends here diff --git a/password-store-ivy.el b/password-store-ivy.el index 3925d30..938895a 100644 --- a/password-store-ivy.el +++ b/password-store-ivy.el @@ -1,13 +1,9 @@ ;;; password-store-ivy.el --- A simple pass frontend for Ivy -*- lexical-binding: t -*- -;; Copyright (C) 2022-2023 Korytov Pavel +;; Copyright (C) 2022-2024 Korytov Pavel ;; Author: Korytov Pavel ;; Maintainer: Korytov Pavel -;; Version: 0.1.0 -;; Package-Requires: ((emacs "27.1") (ivy "0.13.0") (password-store "2.1.4")) -;; Homepage: https://github.com/SqrtMinusOne/org-journal-tags.el -;; Published-At: 2022-02-13 ;; This file is NOT part of GNU Emacs. @@ -26,267 +22,26 @@ ;;; Commentary: -;; A pass frontend based on Ivy, made primarily to use with EXWM and -;; ivy-posframe. -;; -;; This package types stuff with xdotool, so you need to have that -;; available in your $PATH. -;; -;; The only command is `password-store-ivy', which presents an Ivy buffer to -;; select some entry from the pass database. Take a look at its -;; docstring for mode detail. -;; -;; Also take a look at the package README at -;; . +;; Integrate `password-store-completion' with Ivy. ;;; Code: (require 'ivy) -(require 'seq) -(require 'auth-source-pass) (require 'password-store) - -(defgroup password-store-ivy () - "An ivy-based pass frontend." - :group 'password-store) - -(defcustom password-store-ivy-initial-wait 250 - "How much milliseconds to wait before typing characters." - :type 'integer - :group 'password-store-ivy) - -(defcustom password-store-ivy-delay 50 - "Delay between typing characters." - :type 'integer - :group 'password-store-ivy) - -(defcustom password-store-ivy-sequences - '((autotype . (wait - (field . "username") - (key . "Tab") - (field . secret) - (key . "Return"))) - (password . (wait (field . secret))) - (username . (wait (field . "username"))) - (url . (wait (field . "url")))) - "Sequences to execute by `password-store-ivy'. - -It is an alist with the following required keys (corresponding to the -basic actions): -- autotype -- password -- username -- url - -Values are lists of symbols that determine action. Take a look at -`password-store-ivy--get-commands' for available options." - :group 'password-store-ivy - :options '(autotype password username url) - :type '(alist :key-type (symbol :tag "Sequence name") - :value-type (repeat - :tag "Sequence contents" - (choice - (const :tag "Wait for `password-store-ivy-initial-wait'" wait) - (cons - :tag "Wait for milliseconds" - (const :tag "Wait for milliseconds" wait) - (integer :tag "Number of milliseconds to wait")) - (cons - :tag "Enter a field" - (const :tag "Enter a field" field) - (choice - (const :tag "Password" secret) - (const :tag "Username" "username") - (const :tag "URL" "url") - (string :tag "Other field"))) - (cons - :tag "Press a key" - (const :tag "Press a key" key) - (choice - (const "Tab") - (const "Return") - (string :tag "Other key"))))))) - -(defcustom password-store-ivy-end-message "Finished typing" - "A message to show after typing is finished." - :type '(choice - (const :tag "No message" nil) - (string :tag "Message")) - :group 'ivy-pass) - -(defun password-store-ivy--async-command (command callback) - "Run COMMAND in shell asyncronously. - -Call CALLBACK when the command in finished." - (let* ((proc (start-process "pass" nil shell-file-name - "-c" command))) - (set-process-sentinel - proc - (lambda (process _msg) - (pcase (process-status process) - ('exit (funcall callback)) - ('fatal (error "Error in running %s" command))))))) - -(defun password-store-ivy--async-commands (commands &optional callback) - "Run COMMANDS asyncronously. - -Call CALLBACK when the last command is executed." - (if (seq-empty-p commands) - (progn - (when callback (funcall callback)) - (when password-store-ivy-end-message - (message password-store-ivy-end-message))) - (password-store-ivy--async-command - (car commands) - (lambda () - (password-store-ivy--async-commands - (cdr commands) - callback))))) - -(defun password-store-ivy--get-type-command (str) - "Return a command to type STR." - (concat - "printf " - (shell-quote-argument str) - "| xdotool type --clearmodifiers --file - --delay " - (number-to-string password-store-ivy-delay))) - -(defun password-store-ivy--get-wait-command (&optional milliseconds) - "Return a command to sleep for MILLISECONDS. - -If MILLISECONDS is nil, default to `password-store-ivy-initial-wait'." - (format "sleep %f" (/ (float (or milliseconds password-store-ivy-initial-wait)) 1000))) - -(defun password-store-ivy--get-key-command (key) - "Get a command that presses KEY." - (format "xdotool key %s" key)) - -(defun password-store-ivy--get-entry-command (entry field) - "Get a command to type FIELD of ENTRY. - -ENTRY is an alist, FIELD is a symbol or string that can be a key of alist" - (when-let ((contents (alist-get field entry nil nil #'equal))) - (password-store-ivy--get-type-command contents))) - -(defun password-store-ivy--get-commands (entry sequence) - "Get a list of commands to execute for ENTRY. - -SEQUENCE is a list of the following elements: -- `wait'. Wait for `password-store-ivy-initial-wait' milliseconds. -- `(wait )'. Wait for . -- `(key )'. Type . -- `(field )'. Type of entry." - (seq-filter - (lambda (command) (not (seq-empty-p command))) - (mapcar - (lambda (elem) - (unless (sequencep elem) - (setq elem (list elem))) - (pcase (car elem) - ('wait (password-store-ivy--get-wait-command (cdr elem))) - ('key (password-store-ivy--get-key-command (cdr elem))) - ('field (password-store-ivy--get-entry-command entry (cdr elem))) - (_ (error "Wrong field: %s" (prin1-to-string elem))))) - sequence))) - -(defun password-store-ivy--get-entry (entry-name) - "Get a pass entry by ENTRY-NAME." - (let ((entry (auth-source-pass-parse-entry entry-name))) - (unless entry - (user-error "The entry is empty. Perhaps password was incorrect?")) - entry)) - -(defun password-store-ivy--get-sequence (entry sequence-name) - "Get a sequence from an ENTRY. - -SEQUENCE-NAME is a key of `password-store-ivy-sequences'." - (or (when-let ((str (alist-get - (format "sequence-%s" (symbol-name sequence-name)) - entry nil nil #'equal))) - (condition-case err - (car (read-from-string str)) - (error (error "Error in %s: %s" str (prin1-to-string err))))) - (alist-get sequence-name password-store-ivy-sequences))) - -(defmacro password-store-ivy--def-command (name &rest body) - "Create functions to be invoked from `password-store-ivy'. - -NAME is the base name. The first function created, NAME-command, -can be executed inside the `password-store-ivy' completion interface. - -The second function, NAME-action, can be registered as an action, -e.g. with `ivy-set-actions'. - -BODY is put inside both functions, wrapped in the code that makes -the current entry available via the `entry' variable." - (declare (indent 1)) - `(progn - (defun ,(intern (format "%s-command" name)) () - (interactive) - (ivy-exit-with-action - (lambda (entry-name) - (let ((entry (password-store-ivy--get-entry entry-name))) - ,@body)))) - (defun ,(intern (format "%s-action" name)) (entry-name) - (let ((entry (password-store-ivy--get-entry entry-name))) - ,@body)))) - -(password-store-ivy--def-command password-store-ivy--autotype - (password-store-ivy--async-commands - (password-store-ivy--get-commands - entry (password-store-ivy--get-sequence entry 'autotype)))) - -(password-store-ivy--def-command password-store-ivy--password - (password-store-ivy--async-commands - (password-store-ivy--get-commands - entry (password-store-ivy--get-sequence entry 'password)))) - -(password-store-ivy--def-command password-store-ivy--username - (password-store-ivy--async-commands - (password-store-ivy--get-commands - entry (password-store-ivy--get-sequence entry 'username)))) - -(password-store-ivy--def-command password-store-ivy--url - (password-store-ivy--async-commands - (password-store-ivy--get-commands - entry (password-store-ivy--get-sequence entry 'url)))) - -(password-store-ivy--def-command password-store-ivy--fields - (let ((sequences - (mapcar - (lambda (item) - (let ((field-name (car item))) - (when (symbolp field-name) - (setq field-name (symbol-name field-name))) - (if (string-match (rx bos "sequence-") field-name) - `(,field-name - . ,(condition-case err - (car (read-from-string (cdr item))) - (error (user-error "Error in %s: %s" field-name - (prin1-to-string err))))) - `(,field-name . (wait (field . ,(car item))))))) - entry))) - (ivy-read "Field: " sequences - :require-match t - :sort nil - :action (lambda (data) - (password-store-ivy--async-commands - (password-store-ivy--get-commands - entry - (cdr data))))))) - -(defvar password-store-ivy-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "M-a") #'password-store-ivy--autotype-command) - (define-key map (kbd "M-p") #'password-store-ivy--password-command) - (define-key map (kbd "M-u") #'password-store-ivy--username-command) - (define-key map (kbd "M-U") #'password-store-ivy--url-command) - (define-key map (kbd "M-f") #'password-store-ivy--fields-command) - map) - "A keymap for `password-store-ivy'.") +(require 'password-store-completion) (defvar password-store-ivy-history nil "History for `password-store-ivy'.") +(defvar password-store-ivy-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "M-a") #'password-store-completion--autotype-command) + (define-key map (kbd "M-p") #'password-store-completion--password-command) + (define-key map (kbd "M-u") #'password-store-completion--username-command) + (define-key map (kbd "M-U") #'password-store-completion--url-command) + (define-key map (kbd "M-f") #'password-store-completion--fields-command) + map) + "A keymap for `password-store-ivy'.") + ;;;###autoload (defun password-store-ivy () "A frontend for pass. @@ -303,11 +58,11 @@ Available commands: :history 'password-store-ivy-history :keymap password-store-ivy-map :action '(1 - ("p" password-store-ivy--password-action "password") - ("a" password-store-ivy--autotype-action "autotype") - ("f" password-store-ivy--fields-action "fields") - ("u" password-store-ivy--username-action "username") - ("U" password-store-ivy--url-action "url")) + ("p" password-store-completion--password-action "password") + ("a" password-store-completion--autotype-action "autotype") + ("f" password-store-completion--fields-action "fields") + ("u" password-store-completion--username-action "username") + ("U" password-store-completion--url-action "url")) :caller #'password-store-ivy)) (provide 'password-store-ivy)