Blob


1 ;;; simple-pass.el --- Interact with pass -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2022 Free Software Foundation, Inc.
5 ;; Author: Omar Polo <op@omarpolo.com>
6 ;; Version: 1.0
7 ;; Package-Requires: ((emacs "25.1"))
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; Simple wrapper for password-store without unnecessary dependencies.
26 ;;; Code:
28 (defgroup simple-pass nil
29 "Simple Pass."
30 :group 'simple-pass)
32 (defcustom simple-pass-cmd "pass"
33 "Path to the pass executable.")
35 (defcustom simple-pass-dir (expand-file-name ".password-store" (getenv "HOME"))
36 "Path to the password-store repository")
38 (defun simple-pass--copy ()
39 (let ((default-directory simple-pass-dir)
40 (process-file-side-effects))
41 (with-temp-buffer
42 (when (zerop (process-file "find" nil (current-buffer) nil
43 "." "-type" "f" "-iname" "*.gpg"))
44 (goto-char (point-min))
45 (cl-loop until (eobp)
46 collect (buffer-substring-no-properties
47 ;; skip ./
48 (+ 2 (line-beginning-position))
49 ;; skip .gpg
50 (- (line-end-position) 4))
51 do (forward-line +1))))))
53 (defun simple-pass--copy-cr ()
54 "Completion read function for `simple-pass-copy'."
55 (completing-read "Entry: " (simple-pass--copy)))
57 ;;;###autoload
58 (defun simple-pass-copy (pass)
59 "Copy the password for PASS in the `kill-ring'."
60 (interactive (list (simple-pass--copy-cr)))
61 (with-temp-buffer
62 (when (zerop (process-file simple-pass-cmd nil nil nil
63 "show" "-c" pass))
64 (message "copied password for %s" pass))))
66 (provide 'simple-pass)
67 ;;; simple-pass.el ends here