From 8efa6f3f1db166d30a4eb38780f6c47855c51439 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 3 Sep 2023 17:05:49 +0300 Subject: emacs: Modularize --- .emacs.d/modules/thanos-pass.el | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .emacs.d/modules/thanos-pass.el (limited to '.emacs.d/modules/thanos-pass.el') 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 +;; 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 . + +;;; 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/thanosapollo@fastmail.com" "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 -- cgit v1.2.3