-
Notifications
You must be signed in to change notification settings - Fork 9
/
ivy-pass.el
95 lines (76 loc) · 2.44 KB
/
ivy-pass.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; ivy-pass.el --- ivy interface for pass -*- lexical-binding: t -*-
;; Author: ecraven
;; URL: https://github.com/ecraven/ivy-pass/
;; Package-Requires: ((emacs "24") (ivy "0.8.0") (password-store "1.6.5"))
;; Version: 0.1
;; Keywords: pass, password, convenience, data
;; This file is not part of GNU Emacs.
;;; License:
;; Licensed under the GPLv3.
;;; Commentary:
;; Quick start:
;; Install, configure and initialize pass according to https://www.passwordstore.org/
;; run M-x ivy-pass
;; The default action is to copy the password to the kill ring.
;; Other actions (accessible with M-o):
;; - edit an entry (e)
;; - delete an entry (d)
;; - add an entry (a)
;; - rename an entry (r)
;; - generate a new entry (g)
;;; Code:
(require 'ivy)
(require 'password-store)
(defvar ivy-pass-map (make-sparse-keymap))
(ivy-set-actions
'ivy-pass
'(("e"
ivy-pass--edit-action
"edit")
("d"
ivy-pass--delete-action
"delete")
("a"
ivy-pass--add-action
"add")
("r"
ivy-pass--rename-action
"rename")
("g"
ivy-pass--generate-action
"generate")))
(defun ivy-pass--add-action (key)
"Ask for a new key based on KEY, then edit it."
(let ((new-key (read-string "New key: " key)))
(password-store-edit new-key)))
(defun ivy-pass--generate-action (key)
"Ask for a new key based on KEY, then generate an entry and password for it.
Default PASSWORD-LENGTH is ‘password-store-password-length’."
(let ((new-key (read-string "Generate password for new key: " key)))
(password-store-generate new-key)
(password-store-edit new-key)))
(defun ivy-pass--edit-action (key)
"Edit entry for KEY."
(password-store-edit key))
(defun ivy-pass--delete-action (key)
"Delete entry for KEY."
(when (yes-or-no-p (format "Really delete the entry `%s'?" key))
(password-store-remove key)))
(defun ivy-pass--rename-action (key)
"Rename entry for KEY."
(let ((new-name (read-string (format "Rename `%s' to: " key) key)))
(password-store-rename key new-name)))
(defun ivy-pass--password-action (key)
"Add password for KEY to kill ring."
(password-store-copy key))
;;;###autoload
(defun ivy-pass ()
"Select an entry and copy its password to the kill ring."
(interactive)
(ivy-read "Copy password of entry: "
(password-store-list (password-store-dir))
:require-match t
:action #'ivy-pass--password-action
:keymap ivy-pass-map))
(provide 'ivy-pass)
;;; ivy-pass.el ends here