diff --git a/emacs/init.org b/emacs/init.org index e219225..5d43870 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -8,11 +8,16 @@ It's meant to be loaded from init.el like so: (org-babel-load-file (expand-file-name "path/to/init.org")) #+END_SRC -* File Variables +* Prelude Enables lexical binding for everything in init.el: #+BEGIN_SRC emacs-lisp ;;; -*- lexical-binding: t; -*- #+END_SRC + +Requires: +#+BEGIN_SRC emacs-lisp + (require 'json) +#+END_SRC * Default directory #+BEGIN_SRC emacs-lisp (cd "~") @@ -2799,4 +2804,41 @@ The aws-mfa command: (lambda () (message "1Password signin failed, check *op-signin* buffer for details")))) (process-send-string proc (concat master-password "\n")))) + + (defun op-list-items () + (when (not op-token) (1pass-signin)) + (mapcar#'cdr + (mapcar + (apply-partially #'assoc 'title) + (mapcar + (apply-partially #'assoc 'overview) + (json-read-from-string + (funcall + (make-process-fn "op" "list" "items" (format "--session=%s" op-token)))))))) + + (defun op-get-item (item) + (json-read-from-string + (funcall + (make-process-fn "op" "get" "item" (format "--session=%s" op-token) item)))) + + (defun op-get-item-password (item-json) + (let* ((fields (assoc-recursive item-json 'details 'fields)) + (pw-field (car + (seq-filter + (lambda (field) (string= "password" (cdr (assoc 'designation field)))) + fields)))) + (when pw-field (cdr (assoc 'value pw-field))))) + + (defun op-copy-password (item) + (interactive + (list + (ido-completing-read+ "1Password item: " (op-list-items)))) + (if-let ((password (op-get-item-password (op-get-item item)))) + (with-temp-buffer + (insert password) + (copy-region-as-kill (point-min) (point-max)) + (message "Copied password for \"%s\" to kill ring." item)) + (message "No password found in 1Password for \"%s\"." item))) + + (leader-def-key "ao" #'op-copy-password) #+END_SRC