about summary refs log tree commit diff
path: root/users/wpcarro/emacs/pkgs/passage/passage.el
blob: 4a43920e0bed92fa998fe13237bcbfe4ccc7790e (plain) (blame)
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
;;; passage.el --- Emacs passage support -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 William Carroll <wpcarro@gmail.com>

;; Author: William Carroll <wpcarro@gmail.com>
;; Version: 1.0.0

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This package provides functions for working with passage.

;;; Code:

(require 'dash)
(require 'f)
(require 's)

(defgroup passage nil
  "Customization options for `passage'."
  :prefix "passage-"
  :group 'vterm)

(defcustom passage-store
  "~/.passage/store"
  "Path to the passage store directory."
  :type 'string
  :group 'passage)

(defcustom passage-executable
  (or (executable-find "passage")
      "/nix/store/jgffkfdiiwiqa4zqpxn3691mx9xc6axa-passage-unstable-2022-05-01/bin/passage")
  "Path to passage executable."
  :type 'string
  :group 'passage)

(defun passage-select ()
  "Select an entry and copy its password to the kill ring."
  (interactive)
  (let ((key (completing-read "Copy password of entry: "
                              (-map (lambda (x)
                                      (f-no-ext (f-relative x passage-store)))
                                    (f-files passage-store nil t)))))
    (kill-new
     (s-trim-right
      (shell-command-to-string
       (format "%s show %s | head -1" passage-executable key))))
    (message "[passage.el] Copied \"%s\"!" key)))

(provide 'passage)
;;; passage.el ends here