Feedback commit

- PARSE-ID-LINES: Do the work in one pass. Don't build a list to pass to format
  to later iterate through it when we can pass the arguments directly.

- Use REMOVE-if + predicate instead of LOOP/UNLESS/COLLECT

- Don't use m-v-b is we only care about the primary value.

- Use WHEN instead of (if .. .. nil)

- Remove #+sbcl forms.

- Minor Style changes, upcase format directives, use uninterned symbols for
  package designators and strings for system designators.
This commit is contained in:
Javier Olaechea 2019-07-13 13:41:31 -05:00
parent 5675c1200a
commit d100f74e5b
4 changed files with 29 additions and 42 deletions

View file

@ -1,5 +1,4 @@
# gnu-pw-mgr
### _Brandon Invergo <brandon@invergo.net>_
This provides an interface to `gnu-pw-mgr`, GNU's password manager.
Specifically, this provides a command, `password-to-selection`, that
@ -12,6 +11,10 @@ No further configuration is necessary within Stumpwm. You must use
the `gnu-pw-mgr` command-line tool to perform any password
manipulations; this package is only for retrieving passwords.
## Author
_Brandon Invergo <brandon@invergo.net>_
## License
GPL version 3 or, at your option, any later version.

View file

@ -1,11 +1,10 @@
;;;; gnu-pw-mgr.asd
(asdf:defsystem #:gnu-pw-mgr
(asdf:defsystem "gnu-pw-mgr"
:description "Reconstruct passwords with gnu-pw-mgr"
:author "Brandon Invergo <brandon@invergo.net>"
:license "GPLv3"
:version "0.1"
:serial t
:depends-on (#:stumpwm #:cl-ppcre)
:depends-on ("stumpwm"
"cl-ppcre")
:components ((:file "package")
(:file "gnu-pw-mgr")))

View file

@ -16,8 +16,6 @@
(in-package #:gnu-pw-mgr)
(ql:quickload :cl-ppcre)
;; All timer code is blatantly stolen^H^H^H^H^H^Hborrowed from the
;; passwd module.
(defvar *password-id-remember-timeout* 0
@ -28,24 +26,20 @@
(defvar *password-id* nil)
(defvar *password-id-timer*
#+sbcl (sb-ext:make-timer (lambda ()
(setf *password-id* nil)))
#-sbcl (error 'not-implemented))
(sb-ext:make-timer (lambda ()
(setf *password-id* nil))))
(defvar *old-clipboard* nil)
(defvar *clipboard-timer*
#+sbcl (sb-ext:make-timer (lambda ()
(set-x-selection *old-clipboard*)
(setf *old-clipboard* nil)))
#-sbcl (error 'not-implemented))
(sb-ext:make-timer (lambda ()
(set-x-selection *old-clipboard*)
(setf *old-clipboard* nil))))
(defun reset-timer (timer timeout)
#+sbcl (progn
(when (sb-ext:timer-scheduled-p timer)
(sb-ext:unschedule-timer timer))
(sb-ext:schedule-timer timer timeout))
#-sbcl (error 'not-implemented))
(when (sb-ext:timer-scheduled-p timer)
(sb-ext:unschedule-timer timer))
(sb-ext:schedule-timer timer timeout))
(stumpwm:define-stumpwm-type :gpw-password-id (input prompt)
(or *password-id*
@ -54,31 +48,26 @@
(read-one-line (current-screen) prompt :password t)))))
(defun parse-id-lines (lines)
(mapcar (lambda (id-pair)
(format nil "~{~D) ~A~}" id-pair))
(loop for idx from 1
for id in
(loop for id-line in lines
collect (first (cl-ppcre:split " +" id-line)))
collect (list idx id))))
(loop :for index :from 1
:for id-line :in lines
:for id := (first (cl-ppcre:split " +" id-line))
:collect (format nil "~D) ~A" index id)))
(defun label-line-p (line)
(cl-ppcre:scan "^$|^seed-tag|^login id hint:" line))
(stumpwm:defcommand password-to-selection (pwid)
((:gpw-password-id "Password ID: "))
"Prompt for a password ID and a seed ID and set the X selection to
the resulting password."
(let* ((cmd (format nil "exec gnu-pw-mgr '~a'" pwid))
(let* ((cmd (format nil "exec gnu-pw-mgr '~A'" pwid))
(output (stumpwm:run-shell-command cmd t))
(lines (loop for line in (cl-ppcre:split "\\n" output)
unless (or (cl-ppcre:scan "^$" line)
(cl-ppcre:scan "^seed-tag" line)
(cl-ppcre:scan "^login id hint:" line))
collect line))
(lines (remove-if 'label-line-p (cl-ppcre:split "\\n" output)))
(seed (select-from-menu (stumpwm:current-screen)
(parse-id-lines lines)
"seed ID:"))
(seedno (if seed
(parse-integer (first (cl-ppcre:split "\\) " seed)))
nil)))
(seedno (when seed
(parse-integer (first (cl-ppcre:split "\\) " seed))))))
(unless *old-clipboard*
(setf *old-clipboard* (get-x-selection)))
(when (and *clipboard-clear-timeout*
@ -91,7 +80,5 @@ the resulting password."
(when seedno
(stumpwm:set-x-selection
(second (cl-ppcre:split " +" (nth (1- seedno) lines))))
(multiple-value-bind
(s hint)
(cl-ppcre:scan-to-strings "login id hint: .+\\n" output)
(if s (stumpwm:message s))))))
(alexandria:when-let ((string (cl-ppcre:scan-to-strings "login id hint: .+\\n" output)))
(stumpwm:message string)))))

View file

@ -1,7 +1,5 @@
;;;; package.lisp
(defpackage #:gnu-pw-mgr
(:use #:cl :stumpwm)
(:use #:cl #:stumpwm)
(:export #:password-to-selection
#:*password-id-remember-timeout*
#:*clipboard-clear-timeout*))