-
Notifications
You must be signed in to change notification settings - Fork 1
/
password.lisp
62 lines (57 loc) · 2.61 KB
/
password.lisp
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
(in-package :stumpwm-user)
(defvar *master-password* nil
"The master password for the KeePassXC file.")
(defun get-master-password (password-file)
"Read master password for PASSWORD-FILE from StumpWM."
(loop for password
= *master-password*
then (read-one-line (current-screen) (concat password-file " password: ") :password t)
for attempt upto 3
until (or
(= attempt 3)
(when password
(with-input-from-string (st password)
(ignore-errors
(uiop:run-program (list "keepassxc-cli" "ls" password-file)
:input st :output '(:string :stripped t))))))
finally (return (setf *master-password* password))))
(defun get-entry (password-file)
"Choose the entry from PASSWORD-FILE to work (get username/password) on."
(let* ((password (get-master-password password-file))
(entries
(unless (or (equal password '("NIL"))
(equal password nil))
(with-input-from-string (st password)
(remove-if
(lambda (s) (uiop:string-suffix-p s "/"))
(uiop:split-string
(uiop:run-program (list "keepassxc-cli" "ls" password-file)
:input st :output '(:string :stripped t))
:separator '(#\Newline)))))))
(unless (or (equal entries '("NIL"))
(equal entries nil))
(string-trim '(#\Space)
(read-one-line (current-screen) "entry: "
:completions entries :require-match t)))))
(defcommand copy-password () ()
"Copy the password for the given entity in password file."
(let* ((password-file (home "/Documents/p.kdbx"))
(password (get-master-password password-file))
(entry (get-entry password-file)))
(unless (or (equal entry '("NIL"))
(equal entry nil))
(with-input-from-string (st password)
(uiop:launch-program (list "keepassxc-cli" "clip" password-file entry)
:input st)))))
(defcommand copy-username () ()
"Copy the username for the given entity in password file."
(let* ((password-file (home "/Documents/p.kdbx"))
(password (get-master-password password-file))
(entry (get-entry password-file)))
(unless (or (equal entry '("NIL"))
(equal entry nil))
(with-input-from-string (st password)
(uiop:launch-program
(list "keepassxc-cli" "clip" "--attribute" "username"
password-file entry)
:input st)))))