Open jsilve24 opened 2 years ago
Thanks for the code! I'll try to take a look this weekend :-D
I wrote a completing-read interface for quick access to usernames and passwords that I think may be of more broad interest.
I found this useful and patched it into my own system. Thanks! I definitely think it would be valuable in the overall bitwarden.el
package. Thanks also to @seanfarley for creating this in the first place.
One question: what is the expected use case? I added a snippet like below to my init
(setq my-bitwarden-keymap (make-keymap 'my-bitwarden-keymap))
(define-key my-bitwarden-keymap "n" 'bitwarden-kill-username)
(define-key my-bitwarden-keymap "p" 'bitwarden-kill-password)
(define-key my-bitwarden-keymap "u" 'bitwarden-unlock)
(define-key my-bitwarden-keymap "l" 'bitwarden-lock)
(define-key my-mode-map "v" my-bitwarden-keymap) ;; my-mode-map is bound to C-o
and then when I need something I do something like the following:
C-o v u
to call bitwarden-unlock
C-u C-o v n
to call bitwarden-kill-username
with a prefix argument so it lets me search for the name.C-y
to yank the killed usernameC-o v n
to call bitwarden-kill-password
which I think gets the password associated with killed usernameC-y
to yank the killed passwordIs that expected usage or is there a better way?
Way simpler, here is my config:
(use-package bitwarden
:straight (bitwarden :type git :host github :repo "jsilve24/emacs-bitwarden")
:config
(setq bitwarden-user "xxx@xxx.com")
(setq bitwarden-api-secret-key
(plist-get (car (auth-source-search :host "bitwarden.xxx.key"))
:secret))
(setq bitwarden-api-client-id
(plist-get (car (auth-source-search :host "bitwarden.xxx.id"))
:secret))
(setq bitwarden-automatic-unlock
(let* ((matches (auth-source-search :user "xxx@xxx.com"
:host "bitwarden.xxx.user"
:require '(:secret)
:max 1))
(entry (nth 0 matches)))
(plist-get entry :secret)))
;; (bitwarden-auth-source-enable)
(bitwarden-login)
(bitwarden-unlock))
(with-eval-after-load 'exwm
(exwm-input-set-key (kbd "s-u") #'bitwarden-kill-username)
(exwm-input-set-key (kbd "s-p") #'bitwarden-kill-password))
s-u
to pull up a prompt for a login and seleting it by completing read then automatically adds it to the system clipboard (on a timer which auto deletes it as well). tab
to next field (password field), s-p
to get the corresponding password into the clip board. (if you C-u s-p
then it resets the timer and reprompts for a different login to select, otherwise within the timer interval it just guesses you want the corresponding password/username for the most recently selected login entry)So its really just a few key-strokes. My guess is that you are using the C-u prefix because you just called it for some other reason. You only need the C-u prefix if its within the default timer interval (5 min).
First off thanks again for putting this package together.
I wrote a completing-read interface for quick access to usernames and passwords that I think may be of more broad interest. In comparison to the widget interface I find the completing-read interface is faster (feels 2-3 times faster but that's just a guess), feels more natural given my heavy use of minibuffer based completions elsewhere in emacs, and allows copying usernames not just passwords.
The main interface is throught the functions
bitwarden-kill-password
andbitwarden-kill-username
. Since they will often be called one after the other, this code stores both the password and username corresponding to a users selection and does not reprompt if withinbitwarden-time-to-store
. After that time the code automatically unbinds these variables so the passwords are not floating around in free text. A future improvement will also be to clear out the kill ring of these items when unbinding these variables. I just haven't gotten to this yet.If this is something you think would be of broad interest I can make it a pull request. (this is just an exerpt of the relevant code from my config).