Skip to content

Instantly share code, notes, and snippets.

@gnusosa
Last active March 15, 2019 23:27
Show Gist options
  • Save gnusosa/25c7fba916bdb335c11db6251dd618df to your computer and use it in GitHub Desktop.
Save gnusosa/25c7fba916bdb335c11db6251dd618df to your computer and use it in GitHub Desktop.
Get Yubikey OATH token from ykman with Ivy - Emacs
(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