diff options
-rw-r--r-- | .config/emacs/init.el | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el index c9bb5b9..eccc78a 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -952,6 +952,52 @@ By default, returns all jabber related buffers format." :defer t :config (setf password-store-password-length (+ 20 (random 20))) + + (defmacro thanos/make-frame (name &rest body) + "Create temporary frame as NAME. + +Create a temporary frame to execute BODY, which will then be deleted." + `(unwind-protect + (with-selected-frame + (make-frame '((name . ,name) + (fullscreen . 0) + (undecorated . t) + (minibuffer . only) + (width . 70) + (height . 15))) + ,@body + (delete-frame)))) + + (defun thanos/pass-autotype (&optional entry) + "Autotype password ENTRY." + (let* ((entry (or entry (password-store--completing-read t))) + (user (password-store-get-field entry "user")) + (pass (password-store-get entry))) + (start-process-shell-command + "wtype" nil + (format "sleep 0.3 && wtype %s -P tab %s" + (shell-quote-argument (if user user "thanosapollo")) + (shell-quote-argument pass))))) + + (defun thanos/pass-launcher () + "Launch Emacs as a front-end for pass." + (interactive) + (thanos/make-frame + "thanos/pass-launcher" + (let* ((choice (completing-read "Choose an action: " + '("AUTO" "COPY PASS" "EDIT" "GENERATE"))) + (action (pcase choice + ("AUTO" #'thanos/pass-autotype) + ("COPY PASS" #'password-store-copy) + ("EDIT" #'password-store-edit) + ("GENERATE" #'password-store-generate)))) + (funcall action (completing-read "Search: " (password-store-list)))))) + + (defun smtp-get-pass () + "Get password for smtp." + (interactive) + (password-store-copy-field "fastmail.com/[email protected]" "smtp")) + :bind (("C-c p" . 'thanos/pass) :map thanos/pass ("i" . 'password-store-insert) @@ -960,39 +1006,6 @@ By default, returns all jabber related buffers format." ("c" . 'password-store-copy) ("s" . 'smtp-get-pass))) -(defun thanos/pass-launcher () - "Launch Emacs as a front-end for pass." - (interactive) - (unwind-protect - (with-selected-frame - (make-frame '((name . "thanos/pass-launcher") - (fullscreen . 0) - (undecorated . t) - (minibuffer . only) - (width . 70) - (height . 15))) - (let* ((choice (completing-read "Choose an action: " - '("AUTO" "COPY PASS" "COPY USERNAME" "EDIT" "GENERATE"))) - (action (pcase choice - ("AUTO" #'(lambda (entry) (let ((user (password-store-get-field entry "user")) - (pass (password-store-get entry))) - (start-process-shell-command - "wtype" nil - (format "sleep 0.3 && wtype %s -P tab %s" - (shell-quote-argument (if user user "thanosapollo")) - (shell-quote-argument pass)))))) - ("COPY PASS" #'password-store-copy) - ("COPY USERNAME" #'(lambda (entry) (password-store-copy-field entry "user"))) - ("EDIT" #'password-store-edit) - ("GENERATE" #'password-store-generate)))) - (funcall action (completing-read "Search: " (password-store-list))) - (delete-frame))))) - -(defun smtp-get-pass () - "Get password for smtp." - (interactive) - (password-store-copy-field "fastmail.com/[email protected]" "smtp")) - (use-package package-lint :defer t) |