mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
When selecting a password to copy via `pass-copy` I often don't remember the name under which I stored the password. Autocomplete in `pass-copy` helps a bit, but I think a bit more visibility would be nice. This PR adds the function `pass-copy-menu`, which displays the available password entries in a menu. The user can then select or narrow down an entry via autocompletion.
40 lines
1.6 KiB
Common Lisp
40 lines
1.6 KiB
Common Lisp
(defpackage #:pass
|
|
(:use #:cl)
|
|
(:export *password-store*))
|
|
|
|
(in-package #:pass)
|
|
|
|
(defvar *password-store* (merge-pathnames #p".password-store/" (user-homedir-pathname)))
|
|
|
|
(defun pass-entries ()
|
|
(let ((home-ns-len (length (namestring *password-store*))))
|
|
(mapcar
|
|
(lambda (entry)
|
|
(let ((entry-ns (namestring entry)))
|
|
(subseq entry-ns home-ns-len (- (length entry-ns) 4))))
|
|
(directory (make-pathname :directory `(,@(pathname-directory *password-store*)
|
|
:wild-inferiors)
|
|
:name :wild
|
|
:type "gpg")))))
|
|
|
|
(stumpwm:defcommand pass-copy () ()
|
|
"Put a password into the clipboard."
|
|
(let ((entry (stumpwm:completing-read (stumpwm:current-screen)
|
|
"entry: "
|
|
(pass-entries))))
|
|
(stumpwm:run-shell-command (format nil "pass -c ~a" entry))))
|
|
|
|
(stumpwm:defcommand pass-copy-menu () ()
|
|
"Select a password entry from a menu and copy the password into the clipboard."
|
|
(let ((entry (stumpwm:select-from-menu
|
|
(stumpwm:current-screen)
|
|
(mapcar 'list (pass-entries))
|
|
"Copy password to clipboard: ")))
|
|
(stumpwm:run-shell-command (format nil "pass -c ~a" (car entry)))))
|
|
|
|
(stumpwm:defcommand pass-generate () ()
|
|
"Generate a password and put it into the clipboard"
|
|
(let ((entry-name (stumpwm:read-one-line (stumpwm:current-screen)
|
|
"entry name: ")))
|
|
(stumpwm:run-shell-command (format nil "pass generate -c ~a" entry-name))))
|