Last active
March 15, 2019 23:27
-
-
Save gnusosa/25c7fba916bdb335c11db6251dd618df to your computer and use it in GitHub Desktop.
Get Yubikey OATH token from ykman with Ivy - Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defcustom ykman-path "/usr/local/bin/ykman" | |
"Set this to the path of the command line ykman client for your OS.") | |
(defun yubikey-get-oath () | |
"Copy a OATH token to your kill-ring" | |
(interactive) | |
(let ((ivy-hash (make-hash-table :test 'equal)) | |
(cb (lambda (choice) | |
(with-temp-buffer | |
(call-process-region (point-min) (point-max) ykman-path t t nil "oath" "code" (gethash choice ivy-hash)) | |
(let* ((output (buffer-string)) | |
(cells (split-string output)) | |
(code (last cells)) | |
) | |
(kill-new (car code))))))) | |
(with-temp-buffer | |
(call-process-region (point-min) (point-max) ykman-path t t nil "oath" "list") | |
(let ((output (buffer-string))) | |
(dolist (line (split-string output "\n")) | |
(puthash line line ivy-hash) | |
))) | |
(ivy-read "Copy token:" ivy-hash :action cb))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment