summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-07-25 16:21:45 +0300
committerThanos Apollo <[email protected]>2023-07-25 16:21:45 +0300
commit83e83278b744335ceb136832d91a2ef0e906192b (patch)
treea585a4b6014d84a60bec0b1db986c83a9cd5e466
parent286f30a189dadfc3e0de7342eae7f008e6b549c6 (diff)
emacs: Update password management functions
-rwxr-xr-xemacs.org59
1 files changed, 23 insertions, 36 deletions
diff --git a/emacs.org b/emacs.org
index 9b0fc23..8f009d6 100755
--- a/emacs.org
+++ b/emacs.org
@@ -102,7 +102,8 @@ Request the following packages:
gptel
beacon
ement
- mu4e-alert))
+ mu4e-alert
+ pass))
#+end_src
** Installation & activation
Set ~package-archives~, and install packages
@@ -245,41 +246,26 @@ Fonts and basic appearance settings for each device
#+begin_src emacs-lisp
(require 'password-store)
- (defun thanos/get-pass ()
- "Get password entry."
- (interactive)
- (let* ((entry (ivy-read "Search for: " (password-store-list))))
- (when entry
- (condition-case err
- (let* ((user (password-store-get-field entry "user"))
- (pass (password-store-get entry)))
- (start-process-shell-command
- "xdotool" nil
- (if user
- (format "sleep 0.3 && xdotool getactivewindow type '%s' && xdotool getactivewindow key Tab && xdotool getactivewindow type '%s'" user pass)
- (format "sleep 0.3 && xdotool getactivewindow type 'thanosapollo' && xdotool getactivewindow key Tab && xdotool getactivewindow type '%s'" pass))))))))
-
- (defun thanos/edit-pass ()
- "Edit password entry."
- (interactive)
- (let* ((entry (ivy-read "Search for: " (password-store-list))))
- (when entry
- (password-store-edit entry))))
+ (defun thanos/pass-action (action)
+ "Select password entry to perform ACTION."
+ (let ((entry (ivy-read "Search: " (password-store-list))))
+ (funcall action entry)))
- (defun thanos/generate-pass ()
- "Generate password entry."
+ (defun thanos/pass-auto-type (entry)
+ "Autotype Password ENTRY."
(interactive)
- (let* ((entry (ivy-read "Generate: " (password-store-list))))
- (when entry
- (password-store-generate entry (+ 20 (random 20)))
- (password-store-edit entry)
- (insert (format "\nuser:%s" username))
- (server-edit))))
+ (let ((user (password-store-get-field entry "user"))
+ (pass (password-store-get entry)))
+ (start-process-shell-command
+ "xdotool" nil
+ (if user
+ (format "sleep 0.3 && xdotool getactivewindow type '%s' && xdotool getactivewindow key Tab && xdotool getactivewindow type '%s'" user pass)
+ (format "sleep 0.3 && xdotool getactivewindow type 'thanosapollo' && xdotool getactivewindow key Tab && xdotool getactivewindow type '%s'" pass)))))
(defun thanos/pass-launcher ()
"Launch Emacs as a front-end for pass."
(interactive)
- (let* ((ivy-height 100))
+ (let ((ivy-height 100))
(unwind-protect
(with-selected-frame
(make-frame '((name . "thanos/emacs-launcher")
@@ -289,12 +275,13 @@ Fonts and basic appearance settings for each device
(internal-border-width . 10)
(width . 80)
(height . 11)))
- (let ((choice (completing-read "Choose an action: " '("GET" "EDIT" "GENERATE"))))
- (let ((action (pcase choice
- ("GET" #'thanos/get-pass)
- ("EDIT" #'thanos/edit-pass)
- ("GENERATE" #'thanos/generate-pass))))
- (funcall action))
+ (let* ((choice (completing-read "Choose an action: " '("AUTO" "COPY" "EDIT" "GENERATE")))
+ (action (pcase choice
+ ("AUTO" #'thanos/pass-auto-type)
+ ("COPY" #'password-store-copy)
+ ("EDIT" #'password-store-edit)
+ ("GENERATE" (password-store-generate (+ 20 (random 20)))))))
+ (thanos/pass-action action)
(delete-frame))))))
#+end_src
** Keybindings