Add completion for dispass and use dispass-labels
Using `dispass-labels' and parsing its results is probably better than reading and parsing the file itself.
This commit is contained in:
parent
071ef02715
commit
312e06ecab
1 changed files with 44 additions and 23 deletions
67
dispass.el
67
dispass.el
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemsen <tom@ryuslash.org>
|
;; Author: Tom Willemsen <tom@ryuslash.org>
|
||||||
;; Created: Jun 8, 2012
|
;; Created: Jun 8, 2012
|
||||||
;; Version: 1
|
;; Version: 1.1
|
||||||
;; Keywords: processes
|
;; Keywords: processes
|
||||||
;; URL: http://ryuslash.org/projects/dispass.el.html
|
;; URL: http://ryuslash.org/projects/dispass.el.html
|
||||||
|
|
||||||
|
@ -104,6 +104,10 @@
|
||||||
;; - Fix the regular expression used in `dispass-process-filter-for'
|
;; - Fix the regular expression used in `dispass-process-filter-for'
|
||||||
;; to support DisPass v0.1a8.
|
;; to support DisPass v0.1a8.
|
||||||
|
|
||||||
|
;; 1.1 - Use `dispass-label' to get a list of labels the user has
|
||||||
|
;; made, use this for `dispass-list-labels' and adding
|
||||||
|
;; completion options for `dispass'.
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(defgroup dispass nil
|
(defgroup dispass nil
|
||||||
"Customization options for the DisPass wrapper."
|
"Customization options for the DisPass wrapper."
|
||||||
|
@ -122,6 +126,13 @@
|
||||||
:type '(string)
|
:type '(string)
|
||||||
:risky t)
|
:risky t)
|
||||||
|
|
||||||
|
(defcustom dispass-labels-executable "dispass-label"
|
||||||
|
"The location of the dispass-label executable."
|
||||||
|
:package-version '(dispass . "1.1")
|
||||||
|
:group 'dispass
|
||||||
|
:type 'string
|
||||||
|
:risky t)
|
||||||
|
|
||||||
(defcustom dispass-file "~/.dispass"
|
(defcustom dispass-file "~/.dispass"
|
||||||
"The location of your dispass file."
|
"The location of your dispass file."
|
||||||
:package-version '(dispass . "1")
|
:package-version '(dispass . "1")
|
||||||
|
@ -193,6 +204,32 @@ an eye out for LABEL."
|
||||||
(set-process-sentinel proc 'dispass-process-sentinel)
|
(set-process-sentinel proc 'dispass-process-sentinel)
|
||||||
(set-process-filter proc (dispass-process-filter-for label))))
|
(set-process-filter proc (dispass-process-filter-for label))))
|
||||||
|
|
||||||
|
(defun dispass-get-labels ()
|
||||||
|
"Get the list of labels and their information."
|
||||||
|
(let ((result '()))
|
||||||
|
(with-temp-buffer
|
||||||
|
(shell-command (concat dispass-labels-executable
|
||||||
|
" -l --script")
|
||||||
|
(current-buffer))
|
||||||
|
(while (re-search-forward
|
||||||
|
"^\\(\\(?:\\sw\\|\\s_\\)+\\) +\\([0-9]+\\) +\\(\\(?:\\sw\\|\\s_\\)+\\)"
|
||||||
|
nil t)
|
||||||
|
(let ((label (match-string 1))
|
||||||
|
(length (match-string 2))
|
||||||
|
(hashmethod (match-string 3)))
|
||||||
|
(add-to-list 'result
|
||||||
|
(list label
|
||||||
|
`[(,label
|
||||||
|
face link
|
||||||
|
help-echo ,(concat "Generate passphrase for " label)
|
||||||
|
follow-link t
|
||||||
|
dispass-label ,label
|
||||||
|
dispass-length ,length
|
||||||
|
action dispass-from-button)
|
||||||
|
,length
|
||||||
|
,hashmethod])))))
|
||||||
|
result))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun dispass-create (label &optional length)
|
(defun dispass-create (label &optional length)
|
||||||
"Create a new password for LABEL."
|
"Create a new password for LABEL."
|
||||||
|
@ -204,7 +241,11 @@ an eye out for LABEL."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun dispass (label &optional length)
|
(defun dispass (label &optional length)
|
||||||
"Recreate a password previously used."
|
"Recreate a password previously used."
|
||||||
(interactive "MLabel: \nP")
|
(interactive (list
|
||||||
|
(completing-read
|
||||||
|
"Label: " (mapcar (lambda (elm) (elt elm 0))
|
||||||
|
(dispass-get-labels)))
|
||||||
|
current-prefix-arg))
|
||||||
(let ((length (or length dispass-default-length)))
|
(let ((length (or length dispass-default-length)))
|
||||||
(dispass-start-process label nil length)))
|
(dispass-start-process label nil length)))
|
||||||
|
|
||||||
|
@ -250,27 +291,7 @@ thrown."
|
||||||
(setq tabulated-list-entries nil)
|
(setq tabulated-list-entries nil)
|
||||||
|
|
||||||
(let ((tmp-list '()))
|
(let ((tmp-list '()))
|
||||||
(with-temp-buffer
|
(setq tabulated-list-entries (dispass-get-labels))))
|
||||||
(insert-file-contents dispass-file)
|
|
||||||
(while (re-search-forward
|
|
||||||
"\\(\\(?:\\sw\\|\\s_\\)+\\) .*length=\\([0-9]+\\) .*hash=\\(\\sw+\\)$"
|
|
||||||
nil t)
|
|
||||||
(let ((label (match-string 1))
|
|
||||||
(length (match-string 2))
|
|
||||||
(hashmethod (match-string 3)))
|
|
||||||
(add-to-list 'tmp-list
|
|
||||||
`(,label
|
|
||||||
[(,label
|
|
||||||
face link
|
|
||||||
help-echo ,(concat "Generate passphrase for "
|
|
||||||
label)
|
|
||||||
follow-link t
|
|
||||||
dispass-label ,label
|
|
||||||
dispass-length ,length
|
|
||||||
action dispass-from-button)
|
|
||||||
,length
|
|
||||||
,hashmethod])))))
|
|
||||||
(setq tabulated-list-entries tmp-list)))
|
|
||||||
|
|
||||||
(define-derived-mode dispass-labels-mode tabulated-list-mode "DisPass"
|
(define-derived-mode dispass-labels-mode tabulated-list-mode "DisPass"
|
||||||
"Major mode for listing dispass labels.
|
"Major mode for listing dispass labels.
|
||||||
|
|
Loading…
Reference in a new issue