summaryrefslogtreecommitdiff
path: root/.emacs.d/modules/thanos-pass.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-09-03 17:05:49 +0300
committerThanos Apollo <[email protected]>2023-09-03 17:06:54 +0300
commit8efa6f3f1db166d30a4eb38780f6c47855c51439 (patch)
tree873e0c0aeb443c10153a44e14a3d89c938e68e4d /.emacs.d/modules/thanos-pass.el
parentf7c3db0c688b9b98762464cc9e4cc7c87a9dbe96 (diff)
emacs: Modularize
Diffstat (limited to '.emacs.d/modules/thanos-pass.el')
-rw-r--r--.emacs.d/modules/thanos-pass.el91
1 files changed, 91 insertions, 0 deletions
diff --git a/.emacs.d/modules/thanos-pass.el b/.emacs.d/modules/thanos-pass.el
new file mode 100644
index 0000000..edad15e
--- /dev/null
+++ b/.emacs.d/modules/thanos-pass.el
@@ -0,0 +1,91 @@
+;;; thanos-pass.el --- Pass configuration -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Thanos Apollo
+
+;; Author: Thanos Apollo <[email protected]>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'password-store)
+
+(setf password-store-password-length (+ 20 (random 20)))
+
+(defun thanos/pass-launcher ()
+ "Launch Emacs as a front-end for pass."
+ (interactive)
+ (cl-flet ((pass-autotype (entry)
+ (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))))))
+ (let ((ivy-height 100))
+ (unwind-protect
+ (with-selected-frame
+ (make-frame '((name . "thanos/pass-launcher")
+ (minibuffer . only)
+ (fullscreen . 0)
+ (undecorated . t)
+ (internal-border-width . 10)
+ (width . 80)
+ (height . 11)))
+ (let* ((choice (completing-read "Choose an action: " '("AUTO" "COPY PASS" "COPY USERNAME" "EDIT" "GENERATE")))
+ (action (pcase choice
+ ("AUTO" #'pass-autotype)
+ ("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"))
+
+(define-prefix-command 'thanos/pass)
+(global-set-key (kbd "C-c p") 'thanos/pass)
+(define-key thanos/pass (kbd "i") 'password-store-insert)
+(define-key thanos/pass (kbd "e") 'password-store-edit)
+(define-key thanos/pass (kbd "g") 'password-store-generate)
+(define-key thanos/pass (kbd "s") 'smtp-get-pass)
+
+(defun thanos/app-launcher ()
+ "Launch Emacs as an Application Launcher."
+ (interactive)
+ (let ((ivy-height 100))
+ (unwind-protect
+ (with-selected-frame
+ (make-frame '((name . "thanos/emacs-launcher")
+ (minibuffer . only)
+ (fullscreen . 0)
+ (undecorated . t)
+ (internal-border-width . 10)
+ (width . 80)
+ (height . 11)))
+ (counsel-linux-app)
+ (delete-frame)))))
+
+(provide 'thanos-pass)
+;;; thanos-pass.el ends here