Blame


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