Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun my-fixup-gpg-agent (frame)
- "Tweak DISPLAY and GPG_TTY environment variables as appropriate to `FRAME'."
- (when (fboundp 'keychain-refresh-environment)
- (keychain-refresh-environment))
- (if (display-graphic-p frame)
- (setenv "DISPLAY" (terminal-name frame))
- (setenv "GPG_TTY" (terminal-name frame))
- (setenv "DISPLAY" nil)))
- (add-hook 'after-make-frame-functions 'my-fixup-gpg-agent)
- ;; Simple caching
- (defvar my-cached-passwords
- nil
- "Cache of passwords. Stored in plain text so you only want to cache
- them if of low value.")
- (defun my-pass-password (pass-name &optional cache)
- "Return the password for the `PASS-NAME'."
- (let ((cached-pass (assoc-default pass-name my-cached-passwords)))
- (if cached-pass
- cached-pass
- (when (selected-frame)
- (my-fixup-gpg-agent (selected-frame))
- (let ((new-pass (chomp
- (shell-command-to-string
- (format "pass %s" pass-name)))))
- (when (and new-pass cache)
- (add-to-list 'my-cached-passwords (cons pass-name new-pass)))
- new-pass)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement